我如何知道当前 PowerShell 进程的进程 ID (PID)?
Copy-Item \\APPSRVR02\DocExport\*.csv \\APPSRVRWPA\d$\DocImport\ImportFiles\ Remove-Item \\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.
如
所解释。