如何在 Powershell Core 中重定向错误输出?

波提斯

我试图将任何错误重定向到 null,但我似乎无法理解。有什么帮助吗?

这是我的代码: $names | foreach-object{Copy-Item -Path C:\Users\$_\* -Destination C:\Users\$user\Desktop\${_}_removed -Recurse} | out-null

完整的错误文本:
在此处输入图片说明

杰夫·泽特林

我建议您注意有关 PowerShell 重定向Microsoft 文档

要将错误流重定向到 null,您需要应用2>$null到抛出错误的 cmdlet。然而……

据推测,是Copy-Itemcmdlet 引发了错误;如果是这样,与其尝试重定向并丢弃错误流,不如完全禁止它。这可以通过将参数添加-ErrorAction SilentlyContinueCopy-Itemcmdlet来完成

$names | ForEach-Object { Copy-Item -Path C:\Users\$_\* -Destination C:\Users\$user\Desktop\${_}_removed -Recurse -ErrorAction SilentlyContinue }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Powershell Core中解析html

如何在Powershell Core中连接ConnectAzAccount(无提示)?

如何在PowerShell Core(pwsh)中查找或安装缺少的命令?

如何在PowerShell Core中启用语法突出显示?

如何在Linux中从PowerShell Core执行Bash脚本

如何在Powershell Core Azure函数中写入文件

如何在模块内将控制台输出重定向到PowerShell输出?

如何忠实地重定向Powershell中某个工具的控制台输出?

如何将 IF Else 输出重定向到 powershell 中的 html 文件

在Powershell中重定向DLL输出

如何重定向或检索 Powershell 脚本运行的 telnet 进程的输出?

如何在执行过程中将PowerShell的输出重定向到文件

如何在PowerShell中将输出重定向到内存而不是文件?

如何在错误日志文件中重定向成功命令的输出?

如何在F#中重定向标准和错误输出

如何在PowerShell中输出内容

如何在Powershell中实现输出变量?

如何在Powershell中解析输出?

如何在powershell中缩进命令输出

如何在Powershell中输出粗体文本?

如何在powershell中输出xsl:message

如何在C#中对PowerShell Core二进制cmdlet进行单元测试

在 Linux 上重定向输出时如何防止 Powershell 假设输出为 80 列宽

如何在ASP.NET Core中测试https重定向?

如何在ASP.NET Core WebAPI中重定向到操作?

在MVC Core中被AuthenticationHandler重定向后,如何在httpcontext中获取statuscode

如何在 r 中重定向系统命令及其输出?

如何在重定向的php文件中输出新表格?

如何从 .net core 3.1 中的 HandleRequirementAsync 重定向