SOLVED

Modifying a PowerShell Prompt Title called from a Start-Process

%3CLINGO-SUB%20id%3D%22lingo-sub-1848099%22%20slang%3D%22en-US%22%3EModifying%20a%20PowerShell%20Prompt%20Title%20called%20from%20a%20Start-Process%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1848099%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20calling%20from%20one%20PS1%20script%20to%20Start-Process%20to%20call%20another%20instance%20of%20PowerShell%2C%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20works%20as%20expected%20and%20the%20logs%20are%20being%20read%20in%20realtime%20which%20is%20what%20I%20need.%3C%2FP%3E%3CP%3EBut%20after%2014%20logs%20open%2C%20I%20have%2014%20PowerShell%20prompts%20with%20the%20same%20Title%3A%20%3CSTRONG%3EAdministrator%3A%20Windows%20PowerShell.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20know%20you%20can%20modify%20it%2C%20and%20I%20do%20it%20for%20other%20scripts%20with%20no%20problems%2C%20but%20when%20passing%20commands%20to%20a%20new%20instance%2C%20as%20it%20seems%20it%20is%20not%20reading%20my%20%24ScriptBlock%20as%20it%20should%20be.%26nbsp%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EAny%20advice%20on%20what%20I%20may%20be%20doing%20wrong%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESee%20my%20code%20below%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%26lt%3B%23%0AAdd%20parameters%20to%20the%20ScriptBlock%0ASet%20the%20PS%20window%20title%20prompt%20to%20the%20logs%20name%0A%26gt%3B%23%20%0A%0A%24ScriptBlock%20%3D%20%7B%0A%26nbsp%3B%20%24Title%20%3D%20%22Test.log%22%0A%26nbsp%3B%20%24host.ui.RawUI.WindowTitle%20%3D%20%24Title%0A%7D%0A%0A%23%20Start%20a%20new%20PS%20prompt%20executing%20reading%20a%20live%20logfile%0AStart-Process%20powershell.exe%20-ArgumentList%20'-NoExit%20-NoLogo%20-NoProfile%20-ExecutionPolicy%20ByPass%20%24ScriptBlock%3B%20Get-Content%20Test.log%20-Wait%20-tail%2010'%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EThank%20you!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1848099%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1849554%22%20slang%3D%22en-US%22%3ERe%3A%20Modifying%20a%20PowerShell%20Prompt%20Title%20called%20from%20a%20Start-Process%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1849554%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F855643%22%20target%3D%22_blank%22%3E%40Johnnyboysydney%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%3C%2FP%3E%3CP%3Ethe%20title%20should%20be%20within%20the%20script%20block%20and%20also%20make%20sure%20to%20use%20a%20single%20quote%20not%20double%20quote%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24ScriptBlock%20%3D%20%7B%0A%20%24name%3D'New%20Name%20'%0A%20%20%23%24Title%20%3D%20%22C%3A%5CPortQryV2%5Creadme.txt%22%0A%20%20%24host.ui.RawUI.WindowTitle%20%3D%20%24name%0A%7D%0A%0A%23%20Start%20a%20new%20PS%20prompt%20executing%20reading%20a%20live%20logfile%0AStart-Process%20powershell.exe%20-ArgumentList%20%22-NoExit%20-NoLogo%20-NoProfile%20-ExecutionPolicy%20ByPass%20%24ScriptBlock%22%20%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1850807%22%20slang%3D%22en-US%22%3ERe%3A%20Modifying%20a%20PowerShell%20Prompt%20Title%20called%20from%20a%20Start-Process%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1850807%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F790105%22%20target%3D%22_blank%22%3E%40farismalaeb%3C%2FA%3E%26nbsp%3BThank%20you%20so%20much!%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3ESimple%20fix%2C%20wondering%20why%20I%20did%20not%20try%20single%20quotes%20%3Ap%3C%2Fimg%3E%3CBR%20%2F%3EThanks%20again!%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I am calling from one PS1 script to Start-Process to call another instance of PowerShell, 

This works as expected and the logs are being read in realtime which is what I need.

But after 14 logs open, I have 14 PowerShell prompts with the same Title: Administrator: Windows PowerShell.

 

I know you can modify it, and I do it for other scripts with no problems, but when passing commands to a new instance, as it seems it is not reading my $ScriptBlock as it should be. 


Any advice on what I may be doing wrong?

 

See my code below:

 

 

<#
Add parameters to the ScriptBlock
Set the PS window title prompt to the logs name
># 

$ScriptBlock = {
  $Title = "Test.log"
  $host.ui.RawUI.WindowTitle = $Title
}

# Start a new PS prompt executing reading a live logfile
Start-Process powershell.exe -ArgumentList '-NoExit -NoLogo -NoProfile -ExecutionPolicy ByPass $ScriptBlock; Get-Content Test.log -Wait -tail 10'

 

 


Thank you!

 

2 Replies
best response confirmed by Johnnyboysydney (New Contributor)
Solution

@Johnnyboysydney 

Hi

the title should be within the script block and also make sure to use a single quote not double quote 

$ScriptBlock = {
 $name='New Name '
  #$Title = "C:\PortQryV2\readme.txt"
  $host.ui.RawUI.WindowTitle = $name
}

# Start a new PS prompt executing reading a live logfile
Start-Process powershell.exe -ArgumentList "-NoExit -NoLogo -NoProfile -ExecutionPolicy ByPass $ScriptBlock" 

@farismalaeb Thank you so much! 

Simple fix, wondering why I did not try single quotes :p
Thanks again!