Running PSexec from powershell

Welcome Forums General PowerShell Q&A Running PSexec from powershell

This topic contains 4 replies, has 4 voices, and was last updated by

 
Participant
4 years, 4 months ago.

  • Author
    Posts
  • #15989

    Participant
    Points: 0
    Rank: Member

    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

    Keymaster
    Points: 2
    Rank: Member

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

  • #16086

    Participant
    Points: 0
    Rank: Member

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

  • #16087

    Participant
    Points: 0
    Rank: Member

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

  • #16112

    Participant
    Points: 0
    Rank: Member

    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.

The topic ‘Running PSexec from powershell’ is closed to new replies.