使用 Get-Service 时未列出 StartType
StartType not being listed when using Get-Service
我有一个脚本可以检查计算机名称列表中的已知服务列表。它提供了这些服务的状态,并且还应该列出 StartType。输出中未给出 StartType 是否有原因?
在输出中,PSComputerName、ServiceName 和 Status 列包含数据,但 StartType 列保持空白。
$myServices = $PSScriptRoot + "\services.txt" # $PSScriptRoot references current directory
$myServers = $PSScriptRoot + "\servers.txt"
$Log = $PSScriptRoot + "\svclog.csv"
Remove-Item -Path $Log
$serviceList = Get-Content $myServices
$results = Get-Content $myServers
Invoke-command -ComputerName $results -ScriptBlock {
Param($serviceList)
Get-Service $serviceList | Select -Property ServiceName, Status, StartType
} -ArgumentList $serviceList,$Null | Select -Property PSComputerName, ServiceName, Status, StartType |
Export-Csv -NoTypeInformation -Path $Log
我已经在版本 5 上试过了 build: 14409 Revision: 1012
&
版本 5 构建:10586 修订版 117
Get-Service
cmdlet 可能不会 return StartType
属性,但 wmi 确实包含该信息。这应该适合你:
ForEach ($Service in $myServices)
{
Get-WmiObject -ComputerName @(Get-Content -Path $myServers) -Class Win32_Service -Filter "Name='$Service'" |
Select-Object -Property PSComputerName, ServiceName, Status, StartType |
Export-Csv -NoTypeInformation -Path $Log -Append
}
更新以使用 Invoke-Command
:
Invoke-Command -ComputerName $results -ScriptBlock {
ForEach ($service in $using:serviceList)
{
Get-WmiObject -Class Win32_Service -Filter "Name='$service'" |
Select-Object -Property PSComputerName, Name, Status, StartMode
}
} | Export-Csv -NoTypeInformation -Path $Log
我有一个脚本可以检查计算机名称列表中的已知服务列表。它提供了这些服务的状态,并且还应该列出 StartType。输出中未给出 StartType 是否有原因?
在输出中,PSComputerName、ServiceName 和 Status 列包含数据,但 StartType 列保持空白。
$myServices = $PSScriptRoot + "\services.txt" # $PSScriptRoot references current directory
$myServers = $PSScriptRoot + "\servers.txt"
$Log = $PSScriptRoot + "\svclog.csv"
Remove-Item -Path $Log
$serviceList = Get-Content $myServices
$results = Get-Content $myServers
Invoke-command -ComputerName $results -ScriptBlock {
Param($serviceList)
Get-Service $serviceList | Select -Property ServiceName, Status, StartType
} -ArgumentList $serviceList,$Null | Select -Property PSComputerName, ServiceName, Status, StartType |
Export-Csv -NoTypeInformation -Path $Log
我已经在版本 5 上试过了 build: 14409 Revision: 1012 & 版本 5 构建:10586 修订版 117
Get-Service
cmdlet 可能不会 return StartType
属性,但 wmi 确实包含该信息。这应该适合你:
ForEach ($Service in $myServices)
{
Get-WmiObject -ComputerName @(Get-Content -Path $myServers) -Class Win32_Service -Filter "Name='$Service'" |
Select-Object -Property PSComputerName, ServiceName, Status, StartType |
Export-Csv -NoTypeInformation -Path $Log -Append
}
更新以使用 Invoke-Command
:
Invoke-Command -ComputerName $results -ScriptBlock {
ForEach ($service in $using:serviceList)
{
Get-WmiObject -Class Win32_Service -Filter "Name='$service'" |
Select-Object -Property PSComputerName, Name, Status, StartMode
}
} | Export-Csv -NoTypeInformation -Path $Log