To disable a local user account in PowerShell, use the `Disable-LocalUser
` command. This command disables local user accounts.
Here, is the PowerShell code to disable a local user account.
Disable-LocalUser [-Name] <String[]> [-SID] <SecurityIdentifier[]> [-InputObject] <LocalUser[]>
When a user account is disabled, the user can not log on. When a user account is enabled, the user can log on.
In this article, we will discuss how to disable a local user account using the PowerShell Disable-LocalUser command.
Disable a Local User Account Using PowerShell
To disable a local user account in PowerShell, use the Disable-LocalUser
cmdlet with the Name
parameter to specify the local user account name,
Disable-LocalUser -Name "nathan"
In the above PowerShell script, the Disable-LocalUser
cmdlet disables the local user account name specified by the Name
parameter “nathan“.
To check if the user account is disabled or not, use the Get-LocalUser
command as given below.
Get-LocalUser -Name "nathan"
The output of the above PowerShell script gets the local user account details including his name, enable status, and description. It returns the enable status as False, which means the local user account is disabled.
Conclusion
I hope the above article on how to use the Disable-LocalUser
command in PowerShell to disable a local user account is helpful to you.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.