如何获取当前PowerShell进程的进程ID(PID)?
Copy-Item -Path '\\APPSRVR02\DocExport\*.csv' -Destination '\\APPSRVRWPA\d$\DocImport\ImportFiles\' && ` Remove-Item -Path '\\APPSRVRAP02\DocExport\*.csv'
具体来说,我想要一个命令来了解正在执行上述命令的进程的 PID。
Powershell 有一个称为“自动变量”的概念。 这些是主机在启动时定义的变量,所以如果你想知道你正在运行的powershell进程的ID,你只需输入
$PID
,它就会输出你正在运行的powershell进程的ID 。根据您的需要,进程 ID 应该适合您。
[System.Diagnostics.Process]::GetCurrentProcess() ` # Outputs the current process as an object. | Select-Object -ExpandProperty ID # Exposes the ID of that process as a string rather than an object.
如
所解释。