Что вы пытаетесь? Вы должны прийти довольно далеко, используя Get-Service
и Sort-Object
.
Edit: Get-Service
не начать делать время, но есть workaround:
[cmdletbinding()]
param (
[parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[string[]]$ComputerName = $env:computername,
[ValidateNotNullOrEmpty()]
[Alias("ServiceName")]
[string]$Name
)
begin{}
Process {
foreach ($Computer in $ComputerName) {
if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {
Write-Verbose "$Computer is online"
$Service = Get-WmiObject -Class Win32_Service -ComputerName $Computer -Filter "Name='$Name'" -ea 0
if($Service) {
$ServicePID = $Service.ProcessID
$ProcessInfo = Get-WmiObject -Class Win32_Process -ComputerName $Computer -Filter "ProcessID='$ServicePID'" -ea 0
$OutputObj = New-Object -Type PSObject
$OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()
$OutputObj | Add-Member -MemberType NoteProperty -Name Name -Value $Name
$OutputObj | Add-Member -MemberType NoteProperty -Name DisplayName -Value $Service.DisplayName
$OutputObj | Add-Member -MemberType NoteProperty -Name StartTime -Value $($Service.ConvertToDateTime($ProcessInfo.CreationDate))
$OutputObj
} else {
write-verbose "Service `($Name`) not found on $Computer"
}
} else {
write-Verbose "$Computer is offline"
}
}
}
end {}
Изменение строки ниже может позволить вам сделать поиск по шаблону имени службы: $ Service = Get-WmiObject - Класс Win32_Service -ComputerName $ Computer -Filter "Name = '$ Name'" -ea 0 to $ Service = Get-WmiObject -Class Win32_Service -ComputerName $ Computer -Filter "Name LIKE '% $ Name%'" -ea 0 –