SOLVED

Modifying a PowerShell Prompt Title called from a Start-Process

Copper 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 (Copper 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!

1 best response

Accepted Solutions
best response confirmed by Johnnyboysydney (Copper 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" 

View solution in original post