Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Write-Host "(1) Create (2) Rename (3) Remove"
- $Choice = Read-Host
- Try {
- [int] $Choice | Out-Null
- }
- Catch {
- Write-Error "The input has to be from 1 to 3"
- }
- Switch($Choice) {
- 1 {
- Write-Host "Enter username"
- $Username = Read-Host
- Write-Host "Enter password"
- $Password = Read-Host -AsSecureString
- Try {
- New-LocalUser $Username -Password $Password
- }
- Catch {
- $ErrorMessage = $_.Exception.Message
- Write-Error $ErrorMessage
- }
- }
- 2 {
- Write-Host "Enter username to rename"
- $Username = Read-Host
- Write-Host "Enter new username"
- $NewName = Read-Host
- Try {
- Rename-LocalUser $Username -NewName $NewName
- } Catch {
- $ErrorMessage = $_.Exception.Message
- Write-Error $ErrorMessage
- }
- }
- 3 {
- Write-Host "Enter username to remove"
- $Username = Read-Host
- Try {
- Remove-LocalUser $Username
- } Catch {
- $ErrorMessage = $_.Exception.Message
- Write-Error $ErrorMessage
- }
- }
- }
Add Comment
Please, Sign In to add comment