Prevent reading nix config multiple times

This commit is contained in:
Manuel Thalmann 2024-08-27 14:35:04 +02:00
parent 5741d30539
commit 909fd1a2e5
2 changed files with 13 additions and 6 deletions

View file

@ -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;

View file

@ -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);