Loop user creation until it exists
This commit is contained in:
parent
686251b0f7
commit
2c1ea94d97
1 changed files with 16 additions and 9 deletions
|
@ -6,6 +6,7 @@ function New-PersonalUser([Context] $context)
|
||||||
|
|
||||||
if (-not (Get-LocalUser $context.UserName))
|
if (-not (Get-LocalUser $context.UserName))
|
||||||
{
|
{
|
||||||
|
while ($true) {
|
||||||
Write-Host (
|
Write-Host (
|
||||||
[string]::Join(
|
[string]::Join(
|
||||||
"`n",
|
"`n",
|
||||||
|
@ -16,7 +17,13 @@ function New-PersonalUser([Context] $context)
|
||||||
$users = Get-LocalUser | Select-Object { $_.Name };
|
$users = Get-LocalUser | Select-Object { $_.Name };
|
||||||
Read-Host "Please hit enter once you're done...";
|
Read-Host "Please hit enter once you're done...";
|
||||||
|
|
||||||
$user = Get-LocalUser | Select-Object { -not ($users -contains $_.Name) } | Select-Object -Last;
|
$user = Get-LocalUser | Select-Object { -not ($users -contains $_.Name) } | Select-Object -Last -1;
|
||||||
|
|
||||||
|
if ($user) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Rename-LocalUser $user $context.UserName;
|
Rename-LocalUser $user $context.UserName;
|
||||||
Add-LocalGroupMember -Group "Administrators" -Member $user && Set-LocalUser $context.AdminName -Password (ConvertTo-SecureString "Admin");
|
Add-LocalGroupMember -Group "Administrators" -Member $user && Set-LocalUser $context.AdminName -Password (ConvertTo-SecureString "Admin");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue