diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 index ea65c7cf..933d08c5 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -90,101 +90,7 @@ $null = New-Module { Set-Stage ([SetupStage]::CreateUser); } ([SetupStage]::CreateUser) { - $users = @(Get-Users); - $i = Get-CurrentUser; - - for (; $i -lt $users.Count; $i++) { - $name = $users[$i]; - $msAccount = Get-UserConfig -UserName $name "microsoftAccount"; - Set-CurrentUser $i; - - if (Test-Admin) { - Disable-BootMessage; - } - - while ((Get-UserStage) -ne ([UserStage]::Completed)) { - switch (Get-UserStage) { - ($null) { - Set-UserStage ([UserStage]::Create); - continue; - } - ([UserStage]::Create) { - if ($env:UserName -ne $name) { - $userInfo = @{ - name = $name; - msAccount = $msAccount; - }; - - New-ValhallaUser @userInfo; - - if ($msAccount) { - logoff; - } else { - Restart-Intermediate; - } - - exit; - } else { - if ($msAccount) { - if (-not (Test-Admin)) { - Invoke-OneShot DisableUAC; - Restart-Intermediate -NoRegister; - return; - } - - Clear-SetupRegistration; - Disable-OneShotListener; - } - - Set-UserStage ([UserStage]::Configure); - } - } - (([UserStage]::Configure)) { - $displayName = Get-UserConfig -UserName $name "displayName"; - - $userArguments = @{ - name = $name; - }; - - if ($displayName) { - $userArguments.fullName = $displayName; - } - - $adminGroup = @{ - SID = [SecurityIdentifier]::new([WellKnownSidType]::BuiltinAdministratorsSid, $null); - }; - - Set-LocalUser @userArguments; - Deploy-SoftwareAction -Action ([InstallerAction]::ConfigureUser); - Remove-LocalGroupMember -Member "$name" @adminGroup -ErrorAction SilentlyContinue; - - foreach ($group in Get-UserConfig -UserName "$name" "groups") { - Add-LocalGroupMember -Member "$name" -Name "$group"; - } - - if (-not $msAccount) { - net user $name /logonpasswordchg:yes; - } - - Set-UserStage ([UserStage]::Cleanup); - } - ([UserStage]::Cleanup) { - $user = Get-SetupUser; - Disable-LocalUser $name; - Enable-LocalUser $user; - Set-AutologinUser $user; - Unregister-WslDistribution; - Set-UserStage ([UserStage]::Completed); - Restart-Intermediate; - } - } - } - } - - foreach ($user in $users) { - Enable-LocalUser $user; - } - + Install-ValhallaUsers; Set-IsFinished $true; } } diff --git a/scripts/Windows/Scripts/Users.ps1 b/scripts/Windows/Scripts/Users.ps1 index 7deb5231..0badb623 100644 --- a/scripts/Windows/Scripts/Users.ps1 +++ b/scripts/Windows/Scripts/Users.ps1 @@ -2,10 +2,112 @@ using namespace System.Management.Automation.Host; using namespace System.Security.Principal; $null = New-Module { + . "$PSScriptRoot/../Scripts/Deployment.ps1"; . "$PSScriptRoot/../../Common/Scripts/Config.ps1"; . "$PSScriptRoot/../../Common/Scripts/Operations.ps1"; $loggedInUserOption = "LoggedInUser"; + <# + .SYNOPSIS + Installs all pending users to the system. + #> + function Install-ValhallaUsers { + $users = @(Get-Users); + $i = Get-CurrentUser; + + for (; $i -lt $users.Count; $i++) { + Set-CurrentUser $i; + $name = $users[$i]; + $msAccount = Get-UserConfig -UserName $name "microsoftAccount"; + + if (Test-Admin) { + Disable-BootMessage; + } + + while ((Get-UserStage) -ne ([UserStage]::Completed)) { + switch (Get-UserStage) { + ($null) { + Set-UserStage ([UserStage]::Create); + break; + } + ([UserStage]::Create) { + if ($env:UserName -ne $name) { + $userInfo = @{ + name = $name; + msAccount = $msAccount; + }; + + New-ValhallaUser @userInfo; + + if ($msAccount) { + logoff; + } else { + Restart-Intermediate; + } + + exit; + } else { + if ($msAccount) { + if (-not (Test-Admin)) { + Invoke-OneShot DisableUAC; + Restart-Intermediate -NoRegister; + exit; + } + + Clear-SetupRegistration; + Disable-OneShotListener; + } + + Set-UserStage ([UserStage]::Configure); + } + } + ([UserStage]::Configure) { + $displayName = Get-UserConfig -UserName $name "displayName"; + + $userInfo = @{ + name = $name; + }; + + if ($displayName) { + $userInfo.fullName = $displayName; + } + + $adminGroup = @{ + SID = [SecurityIdentifier]::new([WellKnownSidType]::BuiltinAdministratorsSid, $null); + }; + + Set-LocalUser @userInfo; + Deploy-SoftwareAction -Action ConfigureUser; + Remove-LocalGroupMember -Member "$name" @adminGroup -ErrorAction SilentlyContinue; + + foreach ($group in Get-UserConfig -UserName "$name" "groups") { + Add-LocalGroupMember -Member "$name" -Name "$group"; + } + + if (-not $msAccount) { + net user $name /logonpasswordchg:yes; + } + + Set-UserStage ([UserStage]::Cleanup); + } + ([UserStage]::Cleanup) { + $user = Get-SetupUser; + Disable-LocalUser $name; + Enable-LocalUser $user; + Set-AutologinUser $user; + Unregister-WslDistribution; + Set-UserStage ([UserStage]::Completed); + Restart-Intermediate; + } + } + } + } + + foreach ($user in $users) { + Enable-LocalUser $user; + } + } + <# .SYNOPSIS Creates a new user for the PortValhalla setup.