How to get the disabled local user accounts using PowerShell?


To get the disabled local user accounts using PowerShell on the local and the remote system, we can use the WMI or the CIM instance method with the Win32_UserAccount class and the Disabled property to filter the result.

PS C:\> gwmi win32_useraccount | where{$_.Disabled -eq $true}

You can filter out the properties using the specific properties use the Select-Object pipeline command.

PS C:\> gwmi win32_useraccount | where{$_.Disabled -eq $true} | Select Name, FullName, Caption

You can also use the CIM instance method alternatively,

PS C:\> Get-CimInstance win32_useraccount | where{$_.Disabled -eq $true}

To get the disabled accounts on the remote systems, use the -ComputerName parameter in the gwmi or the CIM instance command.

PS C:\> gwmi win32_useraccount -ComputerName Machine1, Machine2 | where{$_.Disabled -eq $true}

The above command will get the disabled local user accounts from the remote machines Machine1 and Machine2.

Updated on: 17-May-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements