The specific instance scripts for service management are as follows:
#$lists = "1.1.1.1", "2.2.2.2" #远程ip列表foreach($list inch $lists){ $uname=' abc '$PWD=convertto-securestring"DEFGH"-asplaintext- Force$cred= New-object System. Management.Automation.PSCredential ($uname,$PWD) Write-output"***************************************"Write-output"*************"$list"*************"Write-output"***************************************"Invoke-command-computername$list-Command {#get-service |where {$_. Name-contains ' MSIServer '}| stop-service-passthru| Set-service-startuptype Disabled #Get-wmiobject Win32_Service | where {$_. Name-contains ' MSIServer '} #get-service |where {$_. Name-contains ' MSIServer '}| Set-service-startuptype Disabled #get-service |where {$_. Name-contains ' MSIServer '}| Start-service-passthruGet-wmiobject Win32_Service | where {$_. Name-contains' MSIServer '}#get-service |where {$_. Name-contains ' CLUSSVC '} #get-service |where {$_. Name-contains ' CLUSSVC '}|set-service-startuptype Automatic |start-service #get-service |where {$_. Name-contains ' MSSQLSERVER '}}-credential$cred}
The relevant comments for the above script are as follows:
#View the health status and properties of a specific serviceGet-wmiobject Win32_Service | where {$_. Name-contains' MSIServer '}#properties and run StateGet-service |where {$_. Name-contains' MSIServer '}#Run Status and description name#Open ServiceGet-service |where {$_. Name-contains' MSIServer '}| Start-service-PassThru#Turn off service # restart restartGet-service |where {$_. Name-contains' MSIServer '}| Stop-service-PassThru#Changing service PropertiesGet-service |where {$_. Name-contains' MSIServer '}| Set-service-startuptype Disabled#where the Startup type has Automatic Disabled Manual
Problems that you may encounter when you use PowerShell to remotely administer a server:
The network can not connect to the Red fork, still be able to surf the internet, this small probability event is due to Windows in the run error will make the system services become unstable and error can not self-restart repair caused by the general need CMD (that is, DOS mode) instructions to restart the project service group is good, must use administrator rights, Recommended to turn off all protection software
net localgroup Administrators LocalService//add
#网络连接模式 can't be a public network
#开启powershell远程管理
Enable-psremoting-force
# Add Trust IP List
Set-item wsman:\localhost\client\trustedhosts *-force
Error in adding the list of trusted IPs, can refer to the link http://www.cnblogs.com/dreamer-fish/archive/2013/03/15/2961497.html
PowerShell Instance Summary (service management)