PowerShell : Using .NET to manage Remote services
On the Scriptinganswers PowerShell forum are some nice threads
especialy JVierra is very active there and gives excelent answers
today I did see this thread :
http://www.scriptinganswers.com/forum/forum_posts.asp?TID=340 ,
it starts about errorhandling but then goes to WMI and services on remote computers and JVierra gives an nice WMI example to wait for a service to stop on a remote computer
I will give a sample of using .NET for this below, again as I explain on my old blog here :PowerShell : Access remote eventlogs :
the CMDlet get-service does not support this but if we use the .net class directly we can use it remote in almost the same way as we work with the get-Service cmdlet after that, for more information see the former post
# Manage remote Services
# do not forget to set a TimeOut on the waitForStatus as ctr-C will not cancel it
[System.ServiceProcess.ServiceController]::GetServices('server')
(new-Object System.ServiceProcess.ServiceController('Service','server')).Start()
(new-Object System.ServiceProcess.ServiceController('Service','server')).WaitForStatus('Running',(new-timespan -seconds 5))
(new-Object System.ServiceProcess.ServiceController('Service','server')).Stop()
(new-Object System.ServiceProcess.ServiceController('Service','server')).WaitForStatus('Stopped'',(new-timespan -seconds 5))
I posted it here also as I not seem to login on the forum at the moment.
Enjoy,
Greetings /\/\o\/\/
Tags : PowerShell