如何获取当前PowerShell进程的进程ID?

问题描述 投票:0回答:2

如何获取当前PowerShell进程的进程ID(PID)?

Copy-Item -Path '\\APPSRVR02\DocExport\*.csv' -Destination '\\APPSRVRWPA\d$\DocImport\ImportFiles\' && `
Remove-Item  -Path '\\APPSRVRAP02\DocExport\*.csv'

具体来说,我想要一个命令来了解正在执行上述命令的进程的 PID。

powershell
2个回答
44
投票

Powershell 有一个称为“自动变量”的概念。 这些是主机在启动时定义的变量,所以如果你想知道你正在运行的powershell进程的ID,你只需输入

$PID

,它就会输出你正在运行的powershell进程的ID 。根据您的需要,进程 ID 应该适合您。

    


5
投票
[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.
获取 PowerShell 进程的进程 ID

所解释。

© www.soinside.com 2019 - 2024. All rights reserved.