Prevent reading nix config multiple times

This commit is contained in:
Manuel Thalmann 2024-08-27 14:35:04 +02:00
parent 95b0f0994e
commit 7535c40a8d
2 changed files with 13 additions and 6 deletions

View file

@ -398,7 +398,12 @@ $null = New-Module {
} }
([UserStage]::Create) { ([UserStage]::Create) {
if ($env:UserName -ne $name) { if ($env:UserName -ne $name) {
New-ValhallaUser $name; $userInfo = @{
name = $name;
msAccount = $msAccount;
};
New-ValhallaUser @userInfo;
if ($msAccount) { if ($msAccount) {
logoff; logoff;

View file

@ -13,10 +13,14 @@ $null = New-Module {
.PARAMETER Name .PARAMETER Name
The name of the user to create. 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 { function New-ValhallaUser {
param( param(
[string] $Name [string] $Name,
[switch] $MSAccount
) )
function Add-MicrosoftAccount { function Add-MicrosoftAccount {
@ -84,9 +88,7 @@ $null = New-Module {
Set-MSAccountName ([string]$newUser); Set-MSAccountName ([string]$newUser);
} }
$msAccount = Get-UserConfig -UserName $Name "microsoftAccount"; if ($MSAccount) {
if ($msAccount) {
if (Test-Admin) { if (Test-Admin) {
Write-Host "Preparing environment for creating MS Account"; Write-Host "Preparing environment for creating MS Account";
Register-Setup -DefaultUser; Register-Setup -DefaultUser;
@ -105,7 +107,7 @@ $null = New-Module {
Write-Host "Creating personal user ``$Name``"; Write-Host "Creating personal user ``$Name``";
if ($msAccount) { if ($MSAccount) {
Add-MicrosoftAccount $Name; Add-MicrosoftAccount $Name;
Set-SetupOption $loggedInUserOption $env:UserName; Set-SetupOption $loggedInUserOption $env:UserName;
Invoke-OneShot ([OneShotTask]::InitializeMSAccount); Invoke-OneShot ([OneShotTask]::InitializeMSAccount);