Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate strings and expression results in PowerShell

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()).Id for the variable doesn't seem to evaluate the expression.

like image 806
EMP Avatar asked Jan 19 '11 23:01

EMP


1 Answers

'My process id is {0}' -f [System.Diagnostics.Process]::GetCurrentProcess().Id

And if we use automatic variables:

'My process id is {0}' -f $pid
like image 149
Andrew Shepherd Avatar answered Nov 09 '22 08:11

Andrew Shepherd