Running PSexec from powershell

This topic contains 4 replies, has 4 voices, and was last updated by  Adam Bertram 4 years, 1 month ago.

  • Author
  • #15989

    Wilfredo Perez

    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.

  • #15990

    Don Jones

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

  • #16086

    H Man

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

  • #16087

    H Man

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

  • #16112

    Adam Bertram

    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 –>

You must be logged in to reply to this topic.