Powershell小技巧--远程对比服务配置
假如你的PS远程运行在两台服务器上,这里有一个简单的脚本教你怎么从每台服务器上得到所有的服务状态并计算他们之间的差别。
$Server1='myServer1'
$Server2='someOtherServer'
$services1=Invoke-Command{Get-Service}-ComputerName$Server1|
Sort-Object-PropertyName,Status
$services2=Invoke-Command{Get-Service}-ComputerName$Server2|
Sort-Object-PropertyName,Status
Compare-Object-ReferenceObject$services1-DifferenceObject$services2-PropertyName,Status-PassThru|
Sort-Object-PropertyName
结果将会输出服务配置的不同之处。
支持PS3.0及以后版本