写主机 =>导出到文件 [英] Write-Host => Export to a file

查看:28
本文介绍了写主机 =>导出到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一些命令的脚本,例如 Write-Host "Server1".如何将其导出到文件中?

I have got a script with some commands such as Write-Host "Server1". How can I export it to a file?

当我尝试使用 script >export.txt 没用.

When I tried with script > export.txt it didn't work.

推荐答案

Write-Host 仅将输出重定向到控制台.

Write-Host redirects the output only to the console.

您可以使用 Write-Output 并重定向到文件(> export.txt 或管道到 Out-File export.txt)

You can use Write-Output and redirect to a file (> export.txt or pipe to Out-File export.txt)

在绝对需要重定向脚本的所有输出的极端情况下,请查看此 cmdlet:

In the extreme case when you absolutely need to redirect all output from a script, take a look to this cmdlet:

Start-Transcript
Get-Help Start-Transcript -full

这篇关于写主机 =>导出到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆