Reputation: 14765
I'm creating some PowerShell code to open a command prompt on a remote machine. This works fine but I can't seem to find a way to set the title of that window, so you can see that you're connected to the remote client.
$ComputerName = 'HostName'
Start-Process 'winrs' -ArgumentList "/r:$ComputerName.domain.net cmd /noprofile /noecho"
I've tried by adding the well known TITLE $ComputerName
at the end, but that doesn't change anything. If setting the title isn't possible, it would be nice to have a comment in the window to see the host name you are connected to.
Upvotes: 0
Views: 1729
Reputation: 200573
The title of a PowerShell window can be changed via the $Host
variable:
$ComputerName = 'HostName'
$Host.UI.RawUI.WindowTitle = $ComputerName
Start-Process 'winrs' -ArgumentList "/r:$ComputerName.domain.net cmd /noprofile /noecho"
Edit: If spawning a new window is not a hard requirement you could change the title of the PowerShell window as described above and run winrs
inline (using the call operator &
):
$ComputerName = 'HostName'
$Host.UI.RawUI.WindowTitle = $ComputerName
& winrs /r:$ComputerName.domain.net cmd /noprofile /noecho
Otherwise you could spawn a new PowerShell window and run the above in that window:
$ComputerName = 'HostName'
Start-Process 'powershell.exe' -ArgumentList "&{`$Host.UI.RawUI.WindowTitle = '$ComputerName'; & winrs /r:$ComputerName.domain.net cmd /noprofile /noecho}"
Note that in this case you must escape the $
in $Host
to prevent premature expansion of that variable (you want it expanded in the child process, not in the parent).
Upvotes: 2
Reputation: 3717
This isn't really a powershell question, since it's more around "How do I manipulate a window started with WinRS?".
That being said, it doesn't seem you can change the title of a window owned by WinRS at all - since even running "Title " manually in the window it creates does nothing. But you could get it to post a comment easily enough by changing your start up command to :
Start-Process 'winrs' -ArgumentList "/r:$ComputerName.domain.net cmd /noprofile /noecho /k echo $ComputerName"
Hope that helps.
Upvotes: 0