0

I'm using following command to get the start time of a windows process. This is to get the running time of a process to terminate if it running too long.

$ProcessStartTime =(Get-Process $WinProcess -computer $computer).StartTime (Not working)

above code not returning Start Time value from a remote server ( it can access other process information). But it getting values for a local process with following command.

$ProcessStartTime =(Get-Process $WinProcess).StartTime (Working)

Can some one help me.

4

2 回答 2

1

您可以使用 wmi 来完成这项工作:

gwmi win32_process -computername $computer| 
? { $_.name -eq "powershell.exe" } | 
% { $_.ConvertToDateTime( $_.CreationDate )}
于 2012-11-30T21:14:25.113 回答
0

我的结果和你一样,但是你可以在远程计算机上创建一个新会话,然后使用调用命令来运行你的脚本:

$sess=new-pssession $computer
$ProcessStartTime =invoke-command -session $sess -ScriptBlock{ (Get-Process $WinProcess).StartTime}
于 2012-11-30T12:29:17.663 回答