[英]powershell: Changing start type of services on a windows 7 machine
Ive wrote a script to get the services of a machine and i want to mirror the StartMode to another machine.我写了一个脚本来获取一台机器的服务,我想将 StartMode 镜像到另一台机器。 I cant think of how to achieve the latter: setting the services on the remote machine.
我想不出如何实现后者:在远程机器上设置服务。 Heres a script ive written so far:
这是我到目前为止编写的脚本:
#List of Issue of services
$NamesOfIssueServices = "Browser", "Dhcp", "Dnscache", "dwmrcs", "iphlpsvc", "LanmanServer", "LanmanWorkstation", "MMCSS", "MpsSvc", "Netlogon", "Netman", "netprofm", "NlaSvc", "nsi", "p2pimsvc","PNRPsvc","PolicyAgent", "SessionEnv", "stisvc", "W32Time", "WinHttpAutoProxySvc", "WinRM"
#get all services
$W32Services = Get-WmiObject Win32_Service
#filter wanted services
$IssueServices = $W32Services | Where-Object {$NamesOfIssueServices -contains $_.name}
#display wanted services
$IssueServices | Sort-Object name | ft Name, DisplayName, State, StartMode, StartName
If you're using PowerShell v2.0 you can easily do that by using the Set-Service cmdlet:如果您使用的是 PowerShell v2.0,您可以使用Set-Service cmdlet 轻松实现:
foreach ($service in $issueServices) {
$startMode = $service.StartMode
if ($service.StartMode -eq "Auto") {
$startMode = "Automatic"
}
Set-Service -ComputerName TheRemoteMachine -Name $service.Name -StartupType $startMode
}
The conditional statement is due to an incompatibility between the value "Auto"
obtained from the StartMode
property and the argument "Automatic"
expected by the -StartupType
parameter.条件语句是由于从
StartMode
属性获得的值"Auto"
与-StartupType
参数期望的参数"Automatic"
之间不兼容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.