Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all remote computer's usernames via Powershell?

Is there any way to get list of all local user accounts on a remote computer via Powershell?

like image 484
Sirwan Afifi Avatar asked Dec 15 '25 01:12

Sirwan Afifi


1 Answers

You can get this with a WMI-query.

function Get-LocalUser ($Computername = $env:COMPUTERNAME) {
    Get-WmiObject -Query "Select * from Win32_UserAccount Where LocalAccount = 'True'" -ComputerName $ComputerName |
    Select-Object -ExpandProperty Name 
}

Get-LocalUser -ComputerName "TestPC1"
like image 94
Frode F. Avatar answered Dec 16 '25 23:12

Frode F.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!