Running PSexec from powershell

Here is the code I have:

forEach ($computer in $computers) {
if (!(test-Connection -Cn $computer -quiet)) {
psexec.exe “\”%$computer% net localgroup users’
} else {
Write-Host $computer is not online


and I would also like each computer name to be in a text file >> c:%cn%.txt

One of the reason I am not using powershell remoting is because the company I work for does not understand the power of powershell so I have to use workarounds.

You can use Get-Content to read a text file’s contents into a variable - like $computers.

psexec \(gc .\computers.txt) -u doamin\user -p p@ssword -h -d powershell.exe “Get-Process”

(gc .\computers.txt) | foreach { psexec \$_ -u doamin\user -p p@ssword -h -d powershell.exe “net localgroup users” }

Rather than depending on psexec, I’d use the [ADSI] type accelerator or WMI to get this information. I’m thinking something like this great post –>