[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Powershell V2.0 : Tasklist on Remote PC

Posted on 2011-04-21
11
Medium Priority
?
2,037 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:ReneGe
  • 7
  • 3
11 Comments
 
LVL 13

Accepted Solution

by:
soostibi earned 1600 total points
ID: 35444270
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
 
LVL 10

Author Comment

by:ReneGe
ID: 35444517
-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
 
LVL 10

Author Comment

by:ReneGe
ID: 35444543
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 13

Expert Comment

by:soostibi
ID: 35444608
Sorry, the mainWindowTitle property is not propageted when called remotely. I try to find an alternative solution.
0
 
LVL 10

Author Comment

by:ReneGe
ID: 35444932
You'r right.

Thanks for looking for an alternative solution.

Cheers,
Rene

0
 
LVL 10

Author Comment

by:ReneGe
ID: 35444967
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
 
LVL 1

Assisted Solution

by:volta82
volta82 earned 400 total points
ID: 35452579
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
 
LVL 10

Author Comment

by:ReneGe
ID: 35452713
Hey Volta,

Thanks. However, it does not show the WindowTitle.

Have any ideas?

Cheers,
Rene
0
 
LVL 10

Author Comment

by:ReneGe
ID: 35509269
Have any new ideas guys?

Cheers,
Rene
0
 
LVL 13

Expert Comment

by:soostibi
ID: 35510482
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
 
LVL 10

Author Comment

by:ReneGe
ID: 35708162
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

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Progress
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question