From aef78935511b85eb049c372e102141eeb2640e53 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 27 Aug 2024 14:35:04 +0200 Subject: [PATCH] Prevent reading `nix` config multiple times --- scripts/Windows/OS/Install.ps1 | 7 ++++++- scripts/Windows/Scripts/Users.ps1 | 12 +++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 index 08d3aa50..3a19f327 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -397,7 +397,12 @@ $null = New-Module { $msAccount = Get-UserConfig -UserName $name "microsoftAccount"; if ($env:UserName -ne $name) { - New-ValhallaUser $name; + $userInfo = @{ + name = $name; + msAccount = $msAccount; + }; + + New-ValhallaUser @userInfo; if ($msAccount) { logoff; diff --git a/scripts/Windows/Scripts/Users.ps1 b/scripts/Windows/Scripts/Users.ps1 index 80cee64b..ac259f84 100644 --- a/scripts/Windows/Scripts/Users.ps1 +++ b/scripts/Windows/Scripts/Users.ps1 @@ -12,10 +12,14 @@ $null = New-Module { .PARAMETER Name The name of the user to create. + + .PARAMETER MSAccount + A value indicating whether the user should be created as a Microsoft Account. #> function New-ValhallaUser { param( - [string] $Name + [string] $Name, + [switch] $MSAccount ) function Add-MicrosoftAccount { @@ -83,9 +87,7 @@ $null = New-Module { Set-MSAccountName ([string]$newUser); } - $msAccount = Get-UserConfig -UserName $Name "microsoftAccount"; - - if ($msAccount) { + if ($MSAccount) { if (Test-Admin) { Write-Host "Preparing environment for creating MS Account"; Register-Setup -DefaultUser; @@ -104,7 +106,7 @@ $null = New-Module { Write-Host "Creating personal user ``$Name``…"; - if ($msAccount) { + if ($MSAccount) { Add-MicrosoftAccount $Name; Set-SetupOption $loggedInUserOption $env:UserName; Invoke-OneShot ([OneShotTask]::InitializeMSAccount);