PowerShell - 如何使用 'Start-Process' 并重命名新启动的窗口标题

标签 powershell

我正在尝试使用 PowerShell(版本 2)Start-Process并重命名新启动的窗口标题。我有以下工作正常的代码片段,它启动一个新的 PowerShell 窗口并跟踪日志($c 包含要跟踪的日志文件):-

Start-Process powershell.exe -Argument "Get-Content", $c, "-wait" 

我不确定如何包含以下内容以便可以更改新启动的窗口标题。

$host.ui.RawUI.WindowTitle = 'New window title rename example text'

干杯。

最佳答案

“肮脏”的解决方案是:

start-process powershell.exe -argument "`$host.ui.RawUI.WindowTitle = 'New window title rename example text'; get-content -Path $c -wait"

我建议为您的命令创建一个脚本并使用参数进行输入。

无题2.ps1
param($c)
$host.ui.RawUI.WindowTitle = 'New window title rename example text'
Get-Content -Path $c -Wait

脚本
$script = Get-Item ".\Desktop\Untitled2.ps1"
$c = Get-Item ".\Desktop\t.txt"
Start-Process powershell.exe -ArgumentList "-File $($script.FullName) -c $($c.FullName)"

关于PowerShell - 如何使用 'Start-Process' 并重命名新启动的窗口标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27607323/

相关文章:

powershell - 获取变量 Powershell 中资源组的位置值

powershell - 是否可以检查 Powershell 中是否给出了 -Verbose 参数?

电源外壳$?变量的行为不符合预期

windows - Powershell Try/catch - 获取用户

shell - 我想同时在多个浏览器中打开一个链接进行测试

powershell - 如何在范围结束时自动调用 Pop-Location

c# - 通过 installutil 将参数传递给服务安装程序

powershell - 在 NuGet 包安装/初始化期间运行的 Powershell 脚本有哪些安全限制?

windows - 如何将多个 zip 解压缩到一个文件夹中,而不使用 zip 名称创建单独的文件夹?电源外壳

arrays - Powershell 将字符串转换为数组