microsoft_windows:adduser_powershell
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| microsoft_windows:adduser_powershell [2025/05/24 23:58] – rodolico | microsoft_windows:adduser_powershell [2025/05/25 01:24] (current) – rodolico | ||
|---|---|---|---|
| Line 113: | Line 113: | ||
| $localGroup = " | $localGroup = " | ||
| } | } | ||
| - | |||
| # Check if user exists, create if not | # Check if user exists, create if not | ||
| if (-not (Get-LocalUser -Name $userName -ErrorAction SilentlyContinue)) { | if (-not (Get-LocalUser -Name $userName -ErrorAction SilentlyContinue)) { | ||
| - | New-LocalUser -Name $userName -Password $securePassword -FullName $fullName -Description $description | + | |
| + | | ||
| + | } catch { | ||
| + | Write-Error " | ||
| + | exit 1 | ||
| + | } | ||
| } | } | ||
| # Set the password (update if user exists) | # Set the password (update if user exists) | ||
| - | Set-LocalUser -Name $userName -Password $securePassword | + | try { |
| + | | ||
| + | } catch { | ||
| + | Write-Error " | ||
| + | exit 1 | ||
| + | } | ||
| # Ensure user is in correct group | # Ensure user is in correct group | ||
| if (-not (Get-LocalGroupMember -Group $localGroup -Member $userName -ErrorAction SilentlyContinue)) { | if (-not (Get-LocalGroupMember -Group $localGroup -Member $userName -ErrorAction SilentlyContinue)) { | ||
| - | Add-LocalGroupMember -Group $localGroup -Member $userName | + | |
| + | | ||
| + | } catch { | ||
| + | Write-Error " | ||
| + | exit 1 | ||
| + | } | ||
| } | } | ||
| + | # Output success message | ||
| + | Write-Host "User ' | ||
| </ | </ | ||
| Line 151: | Line 167: | ||
| * https:// | * https:// | ||
| * https:// | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| Also, thanks to DavidN for tightening it up a little for me. | Also, thanks to DavidN for tightening it up a little for me. | ||
microsoft_windows/adduser_powershell.1748149105.txt.gz · Last modified: 2025/05/24 23:58 by rodolico
