Running PSexec from powershell

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

  • Author
    Posts
  • #15989

    Wilfredo Perez
    Participant

    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
    Keymaster

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

  • #16086

    H Man
    Participant

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

  • #16087

    H Man
    Participant

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

  • #16112

    Adam Bertram
    Moderator

    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 –> http://blogs.technet.com/b/heyscriptingguy/archive/2013/10/27/the-admin-s-first-steps-local-group-membership.aspx.

You must be logged in to reply to this topic.