I want to write out the current process ID in PowerShell. This works:
$processId = $([System.Diagnostics.Process]::GetCurrentProcess()).Id
Write-Output "My process ID is $processId"
However, I want to do it in one line, if possible. Substituting the $([System.Diagnostics.Process]::GetCurrentProcess()开发者_StackOverflow中文版).Id for the variable doesn't seem to evaluate the expression.
'My process id is {0}' -f [System.Diagnostics.Process]::GetCurrentProcess().Id
And if we use automatic variables:
'My process id is {0}' -f $pid
This might be a tad simpler:
$pid
or
"My process id is $pid"
For more info about automatic variables execute:
man about_automatic_variables
Write-Output "My process ID is $([System.Diagnostics.Process]::GetCurrentProcess().Id)"
Basically you just needed to move the closing parenthesis after the Id.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论