Powershell‎ > ‎

Services

Blah

Start Services remotely

Start-service does not have a -computername parameter
IF (Get-PSSnapin | where {$_.name -eq "quest.activeroles.admanagement"}) 
    {write-host "Quest Active Roles snapin already loaded"}
Else
    {add-PSSnapin  quest.activeroles.admanagement}


$ServerList = Get-QADComputer -SearchRoot "blah.com/Servers/"
foreach ($server in $ServerList)
{
    Get-Service -ComputerName $Server.name | where {$_.Displayname -like "RMI*"} | Set-Service -StartupType Automatic
	start-service -InputObject (Get-Service -ComputerName $Server.name | where {$_.Displayname -like "RMI*"})
}


Startup Type startuptype
$services=Get-WmiObject -Class Win32_Service -Filter "StartMode='Auto'"
$services | where {$_.Name -like "*Exchange*"} | select name,displayname, startmode


Using PSRemoting

using powershell remoting to stop start services
$Servers = "server1","server2","server3"

$StopCommand = [ScriptBlock]::Create(@"
Stop-Service W3SVC
Set-Service W3SVC -StartupType Disabled
"@)

$StartCommand = [ScriptBlock]::Create(@"
Set-Service W3SVC -StartupType Automatic
Start-Service W3SVC
"@)

$StatusCommand = [ScriptBlock]::Create(@"
Get-WmiObject -Class Win32_Service -Filter "Name='W3SVC'" | select Name, State, StartMode
"@)

Invoke-Command –ComputerName $Servers { iisreset }
Invoke-Command –ComputerName $Servers –ScriptBlock $StopCommand
Invoke-Command –ComputerName $Servers –ScriptBlock $StartCommand
Invoke-Command –ComputerName $Servers –ScriptBlock $StatusCommand


  

Comments