获取PowerShell进程的进程ID

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

我如何知道当前 PowerShell 进程的进程 ID (PID)?

Copy-Item \\APPSRVR02\DocExport\*.csv \\APPSRVRWPA\d$\DocImport\ImportFiles\
Remove-Item \\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.