惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
O
OpenAI News
W
WeLiveSecurity
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Troy Hunt's Blog
L
LINUX DO - 最新话题
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
H
Heimdal Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Palo Alto Networks Blog
Project Zero
Project Zero
Attack and Defense Labs
Attack and Defense Labs
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Tor Project blog
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
Spread Privacy
Spread Privacy
Cisco Talos Blog
Cisco Talos Blog
T
Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
Google DeepMind News
Google DeepMind News
P
Privacy & Cybersecurity Law Blog
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
Lohrmann on Cybersecurity
Cloudbric
Cloudbric
I
Intezer
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
AI
AI
B
Blog
S
Securelist
P
Proofpoint News Feed
量子位
Jina AI
Jina AI
V2EX - 技术
V2EX - 技术
T
The Exploit Database - CXSecurity.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
CERT Recently Published Vulnerability Notes
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - Coding让生活更美好

Entity Framework search sequnce Runtime Complexity of .NET Generic Collection update the UI property cross thread 打通技术的任督二脉 windbg symbol path 一个文件夹可以link 到另外一个文件夹 Series on Coded UI Test Extensibility Launching the Debugger Automatically 修复软件安装问题和软件卸载问题 How to do code coverage test for windows service EF6 大数据框架整理 技术要点整理 修改table 设置默认值 PowerShell - Special Characters And Tokens To open the project created by previous version of Visual Studio Powershell 转义字符 asp.net Login控件基本属性及事件说明 if test project can't be opened in devenv
获取Powershell write-host 的内容
Coding让生活更美好 · 2012-09-13 · via 博客园 - Coding让生活更美好

如果是在powershell script 内部,想要将write-host的内容输入到一个文本文件,可以使用powershell的输出重定向功能,

可以使用以下方法重定向输出:  

- 使用 Out-File cmdlet,该 cmdlet 将命令输出发送至一个文本文件。通常在需要使用 Out-File cmdlet 的参数(例如 Encoding、Force、Width 或 NoClobber 参数)时 使用该 cmdlet。

- 使用 Tee-Object cmdlet,该 cmdlet 将命令输出发送至一个文本文件,然后将其发送至 管道。

- 使用 Windows PowerShell 重定向运算符。 Windows PowerShell 重定向运算符如下。

运算符 说明 示例 -------- ---------------------- ------------------------------

> 将输出发送到指定文件。 get-process > process.txt

>> 将输出追加到指定文件的内容。 dir *.ps1 >> scripts.txt

2> 将错误发送到指定文件。 get-process none 2> errors.txt

2>> 将错误追加到指定文件的内容。 get-process none 2>> save-errors.txt

2>&1 将错误发送到成功输出流。 get-process none, powershell 2>&1

在不修改script文件的前提下,如果想要获取script文件里write-host的输出,那么该怎么办呢? 

实际上powershell 没有提供再次读取write-host的功能,只能使用windows command 的输出功能来达到这个目的。

比如:   powershell.exe C:\test.ps1 >> C:\test.log 

这句话的意思是调用powershell 来执行test.ps1,然后将所有输出内容重定向到c:\test.log