Powershell V2.0 : Tasklist on Remote PC

Hi there,

I've created a batch file:
@ECHO OFF
FOR /F "delims=" %%A IN ('powershell.exe "C:\Batchfiles\Monitoring\Tasks\PowerShell1.ps1"') DO ECHO %%A
pause

I've created a PowerShell script named "PowerShell1.ps1":
get-process | where {$_.mainWindowTitle} | format-table name, mainwindowtitle -autosize

I Set-ExecutionPolicy in a PS console:
Set-ExecutionPolicy RemoteSigned

Then, run the batch file = Works

NEED:
-To have this to get the processes of a remote XP PC called "\\aremotexppc".
-That the output to be comma separated and without the columns header.

Knowing that I never used Power Shell, please provide me with complete codes and instructions for Powershell V2.0.

Thanks for your help,
Rene
LVL 10
ReneGeAsked:
Who is Participating?
 
soostibiCommented:
This is my suggestion:

Get-Process -ComputerName aremotexppc | Where-Object {$_.mainWindowTitle} | Select-Object -Property name, mainwindowtitle |
    ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1 | Out-File c:\result.txt

1: get-process can be run remotely on its own, as it have a -computername parameter. It uses - I think - WMI remoting under the hood, so it even can run when the target machine doesn't have PowerShell installed.
2: Format-Table is used only for displaying output on the screen, it can not be exported, that is why I use slelect-object, which 'chops' the needed properties.
3: Then I use convertto-csv, as it converts the result end outputs it into the pipeline, so I can further process it.
4: I skip the first object, in this case the first line from the csv.
5: You did not mention, but the final part writes the result to a text file. If you do not need please omit it, then you'll see the result on the screen.
0
 
ReneGeAuthor Commented:
-The command line works when I put my own PC name.
-It does not work on the remote PC

Must Powershell be installed on the remote PC?

If yes, knowing that I am domain admin, would you happen to have a command line or batch file to install "WindowsXP-KB968930-x86-ENG.exe" silently on the remote PC?

I tried:
psexec \\aremotexppc Powershell_2.0_WindowsXP-KB968930-x86-ENG.exe /quiet /forcerestart /overwriteoem /forceappclose /log:C:\ps.log

But it did not work.
0
 
ReneGeAuthor Commented:
Correction:

I tried:
psexec -c \\xpe-recept Powershell_2.0_WindowsXP-KB968930-x86-ENG.exe /quiet /forcerestart /overwriteoem /forceappclose /log:C:\ps.log

And got the following error message code: 1603

Thanks for your help,
Rene
0
WEBINAR: 10 Easy Ways to Lose a Password

Join us on June 27th at 8 am PDT to learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees. We'll cover the importance of multi-factor authentication and how these solutions can better protect your business!

 
soostibiCommented:
Sorry, the mainWindowTitle property is not propageted when called remotely. I try to find an alternative solution.
0
 
ReneGeAuthor Commented:
You'r right.

Thanks for looking for an alternative solution.

Cheers,
Rene

0
 
ReneGeAuthor Commented:
I found this link:
http://www.vistax64.com/powershell/230708-process-list-another-machine.html

I don't know how it can help, but maybe you would know.

Thanks
0
 
volta82Commented:
Run this command to get the prcess from the remote computer as shown below
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Users\Raymond> Get-Process -Name explorer -ComputerName dc01

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
    799      72    27052      44472   259            3756 explorer
0
 
ReneGeAuthor Commented:
Hey Volta,

Thanks. However, it does not show the WindowTitle.

Have any ideas?

Cheers,
Rene
0
 
ReneGeAuthor Commented:
Have any new ideas guys?

Cheers,
Rene
0
 
soostibiCommented:
I think it is beyond the capabilities of the .NET framework, so it's beyond PowerShell. Win32 API calls may solve the problem, but I'm not an expert of that.
0
 
ReneGeAuthor Commented:
Thanks for your help.

I have another thread, trying to do this in VBScript. Here's the link in case you feel like having a look.
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_26971590.html

Cheers,
Rene
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.