foreach ($service in get-content "V:\Program Files\PowerGUI\my
scripts\windows 2003 elective services.txt") {
$newAry = $service.split(',')
$strsvcs = $newAry[0]
$strtype = $newAry[1]
$chkservice = get-service -name $strsvcs -ErrorAction silentlycontinue
If ( ! $chkservice)
{"not installed"}
Else
{set-service $strsvcs -startuptype $strtype
"$strsvcs is $strtype"}
}
$service = get-wmiobject win32_service -computer Server1 -filter
"name='<ServiceName>'"
$service.state
"BarbS" <Ba...@discussions.microsoft.com> wrote in message
news:ECD22465-1A70-4CD6...@microsoft.com...
The user didn't state whether they are using v1 or v2. v2 CTP2 does
support a -computername parameter.
Marco
--
*Microsoft MVP - Windows Server - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com
Half-example of a way to do this with variables and WMI:
$servers="localhost"
$services="alerter","winrm"
foreach($server in $servers){
$result=gwmi -computer $server win32_service
foreach($service in $services){
$result|where{$_.name -eq $service}
}
}
Now, do you want to change all the startup types to the same value or
some may differ?
"Marco Shaw [MVP]" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:OLVbkZK3...@TK2MSFTNGP05.phx.gbl...
Yeah... It was a toss up between one WMI call or multiple... I should
have explained what I was thinking.
That means you're all set?
I would like to jump in at this point.
I seem to have the same problem as BarbS: I can easily disable a local
service, but I couldn't manage to disable a service on a remote machine.
This one works fine:
$MYSERVICE = get-wmiobject win32_service -computer myremotehost -filter
"Name='Themes'"
$MYSERVICE.state = "Stopped"
$MYSERVICE.put()
This one does NOT work (on any machine with any service):
$MYSERVICE = get-wmiobject win32_service -computer myremotehost -filter
"Name='Themes'"
$MYSERVICE.startmode = "Disabled"
$MYSERVICE.put()
I get sort of an acknowledge like
Path : \\dzba9003\root\cimv2:Win32_Service.Name="Themes"
RelativePath : Win32_Service.Name="Themes"
Server : myremotehost
NamespacePath : root\cimv2
ClassName : Win32_Service
IsClass : False
IsInstance : True
IsSingleton : False
I still wonder why, and I can't see this has been solved in this thread so
far.
Can anybody give me a hint?
Greetings
Root
(gwmi win32_service -filter "name='alerter'" -computer localhost).ChangeStartMode("Automatic")
---
Shay Levy
Windows PowerShell MVP
blog: http://blogs.microsoft.co.il/blogs/ScriptFanatic
R> Hi Marco Shaw,
R>
R> I would like to jump in at this point.
R> I seem to have the same problem as BarbS: I can easily disable a
R> local
R> service, but I couldn't manage to disable a service on a remote
R> machine.
R> This one works fine:
R> $MYSERVICE = get-wmiobject win32_service -computer myremotehost
R> -filter
R> "Name='Themes'"
R> $MYSERVICE.state = "Stopped"
R> $MYSERVICE.put()
R> This one does NOT work (on any machine with any service):
R> $MYSERVICE = get-wmiobject win32_service -computer myremotehost
R> -filter
R> "Name='Themes'"
R> $MYSERVICE.startmode = "Disabled"
R> $MYSERVICE.put()
R> I get sort of an acknowledge like
R> Path : \\dzba9003\root\cimv2:Win32_Service.Name="Themes"
R> RelativePath : Win32_Service.Name="Themes"
R> Server : myremotehost
R> NamespacePath : root\cimv2
R> ClassName : Win32_Service
R> IsClass : False
R> IsInstance : True
R> IsSingleton : False
R> I still wonder why, and I can't see this has been solved in this
R> thread so
R> far.
R> Can anybody give me a hint?
R> Greetings
R> Root
R> "Marco Shaw [MVP]" wrote:
R>
Possible values for ChangeStartMode("<StartMode>"):
Boot
Device driver started by the operating system loader. This value is valid
only for driver services.
System
Device driver started by the operating system initialization process. This
value is valid only for driver services.
Automatic
Service to be started automatically by the Service Control Manager during
system startup.
Manual
Service to be started by the Service Control Manager when a process calls
the StartService method.
Disabled
Service that can no longer be started.
To stop the service use the stopService() method:
(gwmi win32_service -filter "name='alerter'" -computer localhost).stopService()
---
Shay Levy
Windows PowerShell MVP
blog: http://blogs.microsoft.co.il/blogs/ScriptFanatic
SL> Try:
SL>
SL> (gwmi win32_service -filter "name='alerter'" -computer
SL> localhost).ChangeStartMode("Automatic")
SL>
SL> ---
SL> Shay Levy
SL> Windows PowerShell MVP
SL> blog: http://blogs.microsoft.co.il/blogs/ScriptFanatic
your answer was about "localhost", but it worked on my remotehost, too.
So, my question is solved.
Thanks so much!
(though, I still wonder why our teacher only told us the "put()" method for
setting WMI-Object properties.)
best regards,
Root
$complist = get-content .\testlist.txt
$services = (Get-WmiObject win32_service -computername $complist |
where-Object { ($_.name -eq "spooler") -and ($_.state -eq
"Stopped")}).startservice()
Do you have one system per line in testlist.txt?
Anything end up in $services?
Marco
--
*Microsoft MVP - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*Co-Author - Sams Windows PowerShell Unleashed 2nd Edition (due December
15th, 2008)
Your command returns a collection of service objects, use foreach to start
them one by one:
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar
N> Can anyone point out where i'm going wrong pls ? I can get my command
N> working when on just a single remote machine but when i adapt to use
N> a variable for a list of machines in text file it fails
N>
N> $complist = get-content .\testlist.txt
N> $services = (Get-WmiObject win32_service -computername $complist |
N> where-Object { ($_.name -eq "spooler") -and ($_.state -eq
N> "Stopped")}).startservice()
N> "Root" wrote:
N>
Your command returns a collection of service objects, use foreach to start
them one by one:
gwmi win32_service -computer (gc .\testlist.txt) -filter "name='spooler'
and state='Stopped'" | foreach {$_.startservice()}
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar
N> Can anyone point out where i'm going wrong pls ? I can get my command
N> working when on just a single remote machine but when i adapt to use
N> a variable for a list of machines in text file it fails
N>
N> $complist = get-content .\testlist.txt
N> $services = (Get-WmiObject win32_service -computername $complist |
N> where-Object { ($_.name -eq "spooler") -and ($_.state -eq
N> "Stopped")}).startservice()
N> "Root" wrote:
N>