Skip to content

Commit

Permalink
feat: use PSCredential for arch user creation
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmckendry committed May 20, 2024
1 parent 1a5ff2c commit e57fef8
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions ps-arch-wsl/ps-arch-wsl.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,22 @@ function New-ArchUser {
#>
param (
[Parameter(Mandatory = $true)]
[string]$Username,
[Parameter(Mandatory = $true)]
[securestring]$Password
[PSCredential]$Credential
)

if (!$Password) {
throw "Failed to read password for $Username."
return
try {
Invoke-ArchScript "echo `"%wheel ALL=(ALL) ALL`" > /etc/sudoers.d/wheel && useradd -m -G wheel $($Credential.GetNetworkCredential().UserName) && echo `"$($Credential.GetNetworkCredential().Password)`" | passwd $($Credential.GetNetworkCredential().UserName) --stdin"
}
catch {
throw "Failed to create user $($Credential.GetNetworkCredential().UserName): $_"
}

# Set the newly created user as the default login
try {
wsl.exe --distribution arch --exec /bin/bash -c "echo `"%wheel ALL=(ALL) ALL`" > /etc/sudoers.d/wheel && useradd -m -G wheel $Username && echo `"$(ConvertFrom-SecureString $Password -AsPlainText)`" | passwd $Username --stdin"
arch config --default-user $Username
arch config --default-user $($Credential.GetNetworkCredential().UserName)
}
catch {
throw "Failed to create user $($Username): $_"
throw "Failed to set default user: $_"
}
}

Expand Down

0 comments on commit e57fef8

Please sign in to comment.