我有一个Powershell脚本来查找特定的服务器及其相应的服务帐户。如果我修改脚本以使用单个服务器和单个服务帐户,结果就是我所期望的。如果我环通的服务器和帐号,我收到以下错误:为什么在循环时我收到RPC服务器不可用错误?
#################################################################
# Find Service Account(s) used to start Services on a Server(s) #
#################################################################
$accounts = (Get-Content C:\Users\location\Scripts\Service_Accounts.txt)
Remove-Item -path C:\Users\location\Scripts\ServiceAccountFnd.txt -force -erroraction silentlycontinue
Import-Module ActiveDirectory # Imports the Active Directory PowerShell module #
## Retrieves servers in the domain based on the search criteria ##
$servers=Get-ADComputer -Filter {Name -Like "namehere*"} -property *
## For Each Server, find the services running under the user specified in $account ##
ForEach ($server in $servers) {
Write-Host $server
ForEach ($account in $accounts) {
Write-Host $account
Get-WmiObject Win32_Service -ComputerName $server | Where-Object {$_.StartName -like "*$account*"} | Format-Table -HideTableHeaders -property @{n='ServerName';e={$_.__SERVER}}, StartName, Name -AutoSize | Out-File -FilePath C:\Users\location\Scripts\ServiceAccountFnd.txt -append -Width 150
}
}
你确定你联系的系统甚至在线吗?大多数情况下,使用这种脚本时,我使用'Test-Connection'来验证服务器甚至在尝试WMI查询之前做出响应。 –
我不是100%确定的,也许99.9%肯定:-)但会使用您的建议来测试连接。谢谢。 – Gringo
你好。你可以尝试用这个'$ servers = Get-ADComputer -Filter {Name-Like“namehere *”} -property来替换这个'$ servers = Get-ADComputer -Filter {Name-Like'这里*“} -property *' * |选择名称就像vrdse在回答 – Vitaly