Powershellを使用して、実行中のすべてのサービスを、開始時刻の降順で並べ替えられたリストとして一覧表示するにはどうすればよいですか?
ありがとう
Powershellを使用して、実行中のすべてのサービスを、開始時刻の降順で並べ替えられたリストとして一覧表示するにはどうすればよいですか?
ありがとう
何を試しましたか?とを使用してかなり遠くに来る必要がGet-Service
ありSort-Object
ます。
編集:Get-Service
開始時間はありませんが、回避策があります:
[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 {}