Get process ID from a remote computer

I need help with the PS script, this is my first try and the first post on this forum.
I never used or tried PS before.
I’m not sure where even to post…

I’m trying to write a PS script to get processes running on a remote computer.
Microsoft documents have this example:
“Get-Process -Name PowerShell -ComputerName localhost, Server01, Server02”
But like everything at Microsoft, it is confusing and not clear.
I tried this:
Get-Process powershell -ComputerName someone-desk2
Get-Process powershell -someone-desk2
Get-Process powershell -ComputerName localhost,someone-desk2
Nothing is working…
Thank you

Welcome to the forum. :wave:t4:

First of all … Please when you post code, error messages, console output or sample data fromat it as code using the preformatted text button ( </> ).
Thanks in advance.

Unfortunately that’s not a helpful description. What exactly happens? Do you get error messages? If yes please show them (formatted as code :wink: )

I see!

Here is the error:
Get-Process : Couldn’t connect to remote machine.
At line:1 char:2

  • Get-Process powershell -ComputerName desk2
  •  + CategoryInfo          : NotSpecified: (:) [Get-Process], InvalidOperationException

I pinged the Host (desk-2) it is online and returns the IP. I can remotely log in to the PC.

Please format errors and code as code.
Thanks in advance.

That does not necessarily mean you can reach the remote computer with PowerShell remoting.

You should check/enable PowerShell remoting. Here are some links about that topic:

The computername parameter uses dcom, no?

I should have been following my own recommendation - to read the complete help topic. :flushed: You’re totally right. Get-Process is one of those cmdlets.

So it might be a firewall issue …

@tester_v you may check your firewall settings on the remote computer to allow DCOM connections.

I have the user name and the password for the systems, I can map a drive to my server and copy/paste anything to it. I do not think it is a firewall. I also enabled “PowerShell remoting” on the remote host to see if it’ll help, still not working. I started sinking if I could start a ‘program’ on a remote host. I found this script online :
powershell.exe -c "$user='WORKGROUP\John'; $pass='password123'; try { Invoke-Command -ScriptBlock { Get-Content C:\Users\John\Desktop\secret.txt } -ComputerName Server123 -Credential (New-Object System.Management.Automation.PSCredential $user,(ConvertTo-SecureString $pass -AsPlainText -Force)) } catch { echo $_.Exception.Message }" 2>&1

I replaced ‘WORKGROUP’ with ‘DOMAIN’ in the original script.

It fails with exception error:

`powershell.exe : =DOMAIN\John : The module ‘=DOMAIN’ could not be loaded. For more information, run ‘Import-Module =DOMAIN’.
At line:1 char:1

  • powershell.exe -c "$user=‘DOMAIN\John’; $pass=‘password123,’; try { Invo …
  •   + CategoryInfo          : NotSpecified: (=DOMAIN\John :...t-Module =DOMAIN'.:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError

At line:1 char:1

  • =‘DOMAIN\John’; =‘password123,’; try { Invoke-Command -ScriptBlock { Get …
  •   + CategoryInfo          : ObjectNotFound: (=DOMAIN\John:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CouldNotAutoLoadModule

=password123, : The term ‘=password123,’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:18

  • =‘DOMAIN\John’; =‘password123,’; try { Invoke-Command -ScriptBlock { Get …
  •              ~~~~~~~~~~~
    • CategoryInfo : ObjectNotFound: (=password123,:String) , CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException`

Thank you for taking the time to help me, I have no idea what I’m doing.
I’m not sure I’m formating the printout correctly, sorry about that! I"m using ’ </>’ button.
I really appreciate your help

Funny you say that. :wink: :smiley:

Next time you click on that button FIRST and then paste your code where you will be told. :wink:

I assume you work in an AD domain environment. And I assume you have an account who is administrator on the remote pc you want to reach. Let’s try the following: You copy the following line s of code completely to your PowerShell_ISE script pane. You fill in the computer name of the remote computer you want to reach. Then you select all of the code with the mouse and hit .

$Credential = Get-Credential
Invoke-Command -ComputerName 'Remote Computers name' -Credential $Credential -ScriptBlock {

It will ask you for an account with password. You have to provide an administrative account.

The result you get should look like this … just much more:

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName      PSComputerName
-------  ------    -----      -----     ------     --  -- -----------      --------------
    124       8     1688       5136       0,48  11232   0 armsvc           RemotePC      
   1314      49    56440      95804     173,22   4132   0 CcmExec          RemotePC      
    258      16     3364      10120       1,02   4764   0 CmRcService      RemotePC      
    102       6     6236       4788       0,03   5208   0 conhost          RemotePC      
    725      26     2088       4252       7,86    844   0 csrss            RemotePC      
    175      13     1604       3532       0,67    940   1 csrss            RemotePC      
    744      27    15344      38472       4,95   1628   1 dwm              RemotePC      
     32       5     1572       2948       0,30   1232   1 fontdrvhost      RemotePC      
     32       5     1668       3096       0,45   1248   0 fontdrvhost      RemotePC      
      0       0       60          8                 0   0 Idle             RemotePC      
    179      10     1904       7848       0,92   2544   0 igfxCUIService   RemotePC      
    156       8     1492       5884       3,02   2080   0 IntelCpHDCPSvc   RemotePC      

Olaf! You are DA MAN bro!
Yep! DA MAN!

I’m confused about PS and I’m confusing others Sorry about that!
Just for testing purposes, I used two systems (PCs) that both have the same account as an Admin.
Just to make sure PS scripts will work in the simplest environments. And I found they do!
I have no problem pulling a"Processes list" or starting a Python script.
Problems arrive when I’m trying to work with a remote host that does not have my user account added to the Admin group but I have a User Name and the Pass for that Remote Host to log in.

So, I need to add Credentials to my script, and that is a HUGE problem for me.
the oneliner below works great if I ran it from my laptop to my desktop (they have both have the same account)

Invoke-Command -ComputerName someoone-desk2 -ScriptBlock {Get-Process} 

I need to add to the oneliner 'new UserName/Pass" in order to connect to a remote host. Need t to add credentials

$cred = "$username","$password"

I’m not sure how to do that correctly…

The second script starts a python script, I just need to add credentials to it too…

Invoke-Command -Computer someone-DESK2 -Scriptblock {python.exe 'C:\Python_Test\Remote_Access\'}

I think I’m getting much better with the formating text and pasting the code :wink:

You do actually. :+1:t4: :slightly_smiling_face:

I actually showed that in my last answer. You use Get-Credential. Please read the help completely including the examples to learn how to use it.

Some general tipps:
In order to connect to a remote computer you have to have an administrative account for the remote computer. And just because the accounts on two computers have the same name and the same password does not mean they are the same account. The “full name” of the account on computer1 is “computer1\SomeAccount” and on computer2 it is “computer2\SomeAccount”.

If you’re working in an AD domain the easiest way to connect to other remote computers is to use an account who is member of the local administrators group of those remote computers and in this way avoid the need to explicitly provide credentials for your commands or scripts.

I have read it, it is as confusing as anything created by Microsoft… Each time I’m reading their docs I’m wondering are they written by a human or some kind of typing monkey?

I don’t know what to answer … less complains more actions. :blush: :stuck_out_tongue_winking_eye: :man_shrugging:t4:

Just like the code by itself so is the documentation open source. I’d think when you’re able to improve it you’re welcome to join. :wink: