相关疑难解决方法(0)

将Write-Host语句重定向到文件

我有一个PowerShell脚本,我正在调试,并希望将所有写主机语句重定向到一个文件.有一个简单的方法吗?

powershell

17
推荐指数
5
解决办法
7万
查看次数

PowerShell 重定向并不总是有效

重定向警告流New-PSSession,因为我相信它应该不起作用。无论我尝试抑制/重定向它做什么,我总是收到以下(黄色)警告消息到控制台:

WARNING: Using New-PSSession with Basic Authentication is going to be deprecated soon, checkout https://aka.ms/exops-docs for using Exchange Online V2 Module which uses Modern Authentication.
Run Code Online (Sandbox Code Playgroud)

PowerShell 重定向/流允许该消息渗透到控制台/std_out,我错过了什么?

什么不起作用

根据互联网的智慧,我尝试了以下方法:

New-PSSession *>$null ...
Run Code Online (Sandbox Code Playgroud)
New-PSSession ... | Out-Null
Run Code Online (Sandbox Code Playgroud)
New-PSSession *>$null ... -OutVariable x -ErrorVariable y -WarningVariable z
Run Code Online (Sandbox Code Playgroud)
New-PSSession *>$null ... -WarningAction SilentlyContinue
Run Code Online (Sandbox Code Playgroud)
$WarningPreference = 'SilentlyContinue'
New-PSSession ...
Run Code Online (Sandbox Code Playgroud)

我什至尝试临时控制std_out

$std_out = [System.Console]::Out
$out_writer = New-Object IO.StringWriter
[System.Console]::SetOut($out_writer)

$std_err = [System.Console]::Error
$err_writer = New-Object IO.StringWriter …
Run Code Online (Sandbox Code Playgroud)

powershell

9
推荐指数
1
解决办法
712
查看次数

隐藏写主机输出

我正在编辑一个我需要转换为exe的脚本.它Write-Host在运行时有一些脚本状态的输出.这导致脚本的exe向用户显示对话框,迫使他们在脚本完成之前单击OK 3或4次.

我想保留Write-Host输出但只是在最终用户从exe执行它时隐藏它们(对话框).

这可能吗?我已经查看[void]了代码不喜欢的内容.我可以开始工作的另一种方式就是用它来评论#,但我确信有更好的方法.

我想要隐藏/抑制的示例:

Write-Host "Current Status = " $status
Run Code Online (Sandbox Code Playgroud)

powershell

2
推荐指数
1
解决办法
862
查看次数

标签 统计

powershell ×3