I have created a long running process from powershell which runs a command for quite some time as follows:
Start-process "powershell" "long running command"
I want to give this process a custom name or some kind of tag of type string to refer the process later.
Is this possible to name a powershell process launched from powershell ?
I can't use pid in my case because we have to provide our client process-search ability using a name provided by him.
You could have your script modify the WindowTitle property at the start of its execution, as follows:
$host.ui.RawUI.WindowTitle = 'Your Custom Title'
You could then identify your specific process by using Get-Process powershell
and checking the MainWindowTitle
property.
Get-Process PowerShell | Where-Object { $_.MainWindowTitle -eq 'Your Custom Title' }
There are likely other options also, such as running the process under a specific user account or by targetting a specific PowerShell configuration endpoint and then specifying that when running the PowerShell.exe process via the -ConfigurationEndpoint
switch. These require config to be added in advance however, where as modifying the title to something you know will be unique is quite a simple solution.