Running PSexec from powershell

This topic contains 4 replies, has 4 voices, and was last updated by Profile photo of Adam Bertram Adam Bertram 2 years, 6 months ago.

  • Author
    Posts
  • #15989
    Profile photo of Wilfredo Perez
    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
    Profile photo of Don Jones
    Don Jones
    Keymaster

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

  • #16086
    Profile photo of H Man
    H Man
    Participant

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

  • #16087
    Profile photo of H Man
    H Man
    Participant

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

  • #16112
    Profile photo of Adam Bertram
    Adam Bertram
    Participant

    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.