header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Starting services on Remote desktops with PS
Last Post 14 May 2008 06:38 PM by chris.harrod. 3 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
raylor9355User is Offline
New Member
New Member
Posts:1

--
07 May 2008 05:20 PM  

I have 200 XP machines that require a service to be started. I am trying to use Powershell to sort through a list of workstations and restart a specific service is it is stopped. I am new to Powershell, I have been using PSexec to connect to the new machines and start the service. Any help would be appreciated. I saw some post about the rget-service command, but it fails on me.

Ray

BauerShellUser is Offline
New Member
New Member
Posts:7

--
08 May 2008 11:58 AM  

$remoteservice = (get-wmiobject -class "Win32_Service" -namespace "root\CIMV2" -computername HOSTNAME | where {$_.Displayname -like "DISPLAYNAME"})

$remoteservice.StartService()

Have Fun/BS

halr9000User is Offline
Basic Member
Basic Member
Posts:303

--
08 May 2008 12:28 PM  

Sweet, I had no idea Jack Bauer used PowerShell.

Anyway, to finish up the example, here's how you can loop on your 200 boxes:

$ServiceName = "My Service"
get-content computers.txt | % {
$remoteservice = gwmi win32_service -comp $_ | ? { $_.displayname -like $ServiceName }
$remoteservice.StartService()
}

Note the use of aliases:
% = foreach-object
gwmi = get-wmiobject
? = where-object (or its other alias "where")

chris.harrodUser is Offline
New Member
New Member
Posts:4

--
14 May 2008 06:38 PM  
Eh, I think I found some XSS problems while nesting code tags we might want to look at.
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer