Managing Windows Local Users with PowerShell
-
Now that PowerShell has become the primary way to manage Windows machines, tasks such as local user management that were traditionally done with net user command can be done right from inside of PowerShell. The commands for managing local users are part of the LocalAccounts commandlet.
It is important to note that these commandlets are not part of PowerShell proper and are not available in all PowerShell versions. Also, while this is the "PowerShell way" to do user management, older methods like the net commands are stand alone utilities and work equally well from PowerShell as from any other calling method.
List Local Users
Get-LocalUser
Get Details of Specific Local User
Get-LocalUser "sally"
Create a New Local User
This command is quite a bit more unnecessarily obtuse than its use or Linux counterparts, in an attempt to enforce potentially unwanted password decisions, simply passing the password is not possible with this command. So we have to do two steps instead of just one. Note this can make PS very hard to use in some remote command execution systems where variables are lost between commands.
First we have to set the password in a variable, before we can create the user.
Creating a password interactively:
$Password = Read-Host -AsSecureString
Or creating a password directly in the command:
$TempPass = "mySecret" $Password = ConvertTo-SecureString -AsPlainText $password -Force
Now that we have set the variable that we will use, we can pass it to the user creation command.
New-LocalUser -Name "sally" -Password $Password
Delete a Local User
Remove-LocalUser -Name sally
LocalAccounts Command Guide on Microsoft
Part of a series on Windows Systems Administration by Scott Alan Miller
-
Part of a series on WIndows Systems Administration by Scott Alan Miller
Can we get a link to this?
-
@WrCombs said in Managing Windows Local Users with PowerShell:
Part of a series on WIndows Systems Administration by Scott Alan Miller
Can we get a link to this?
I've not put the ToC together yet. But the tag works.
-
@scottalanmiller said in Managing Windows Local Users with PowerShell:
@WrCombs said in Managing Windows Local Users with PowerShell:
Part of a series on WIndows Systems Administration by Scott Alan Miller
Can we get a link to this?
I've not put the ToC together yet. But the tag works.
sweet - thanks.
I have some interest in Windows Administration , Thanks -
@WrCombs said in Managing Windows Local Users with PowerShell:
@scottalanmiller said in Managing Windows Local Users with PowerShell:
@WrCombs said in Managing Windows Local Users with PowerShell:
Part of a series on WIndows Systems Administration by Scott Alan Miller
Can we get a link to this?
I've not put the ToC together yet. But the tag works.
sweet - thanks.
I have some interest in Windows Administration , ThanksMe too
-
so ugly compared to using bash in linux...I just hate the way powershell syntax is.
-
@StuartJordan said in Managing Windows Local Users with PowerShell:
so ugly compared to using bash in linux...I just hate the way powershell syntax is.
What does the syntax in linux "using bash" look like?
-
@WrCombs In regards to adding users on Linux..not adding Windows users.
-
even the net user command looks cleaner:
"net localgroup administrators username /add"
But yep, powershell is the future and that is now defunct....
-
the only bonus, you do get tab completion is powershell...mainly because you need it for the long ass commands lol
-
@StuartJordan said in Managing Windows Local Users with PowerShell:
the only bonus, you do get tab completion is powershell...mainly because you need it for the long ass commands lol
Self fulfilling need
-
@StuartJordan said in Managing Windows Local Users with PowerShell:
even the net user command looks cleaner:
"net localgroup administrators username /add"Yeah, faster, simpler, easier, more obvious, more memorable.
-
@WrCombs said in Managing Windows Local Users with PowerShell:
@StuartJordan said in Managing Windows Local Users with PowerShell:
so ugly compared to using bash in linux...I just hate the way powershell syntax is.
What does the syntax in linux "using bash" look like?
So definitely "using Bash" needs quotes, it's "in standard UNIX" and Bash just calls it. It's really Windows vs. Linux here rather than PowerShell vs Bash. But the "official" Windows way is this PS CmdLet mess. The standard Linux way looks like this...
useradd sally
Then to add a password all at once is more complex. net user is the winner of simplicity.
Here is how you do a single line add with useradd in Linux...
useradd -p $(echo mysecret | openssl passwd -1 -stdin) sally
-
Topic has been forked, please keep discussions of OS comparisons to a different thread.