易碎的温柔 發表於 2025-8-14 11:21:25

win10怎么将命令提示符或PowerShell命令输出保存到txt文本文件?

<p>在使用 Windows 10 操作系统时,将 PowerShell 或「命令提示符」的输出内容保存到文本文件,在许多情况下都能够派上大用场。例如,当您在用命令进行 Troubleshooting 时,将命令输出保存到 TXT 中进行分析会比较方便,也便于提交给其它 IT Pro 请求帮助。</p>
<p>虽然在新版 Windows 10 中,用户已经可以非常方便在 CMD 或 PowerShell 窗口中对选定内容进行复制、粘贴,但步骤也多了不是?下面就为大家介绍,如何将「命令提示符」或 PowerShell 命令结果直接重定向输出到 TXT 文本文件。</p>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202508/202508141113081001.jpg" /></p>
<h3>将「命令提示符」命令输出保存到文本文件</h3>
<p>要将「命令提示符」输出结果保存到文本文件,请使用以下步骤:</p>
<p>1、在「开始」菜单中搜索&nbsp;cmd&mdash;&mdash;右击「命令提示符」&mdash;&mdash;选择「<strong><a href="https://www.jb51.net/os/win11/987138.html" target="_blank">以管理员身份运行</a></strong>」</p>
<p>2、执行以下命令以将输出保存到文本文件:</p>
<div class="jb51code"><pre class="brush:xhtml;">command &gt; D:\output.txt</pre></div>
<p>上述示例中&nbsp;command&nbsp;代表您所执行的命令,&nbsp;&gt;&nbsp;表示输出符号,&nbsp;D:\output.txt&nbsp;表示要输出到的文本文件路径。</p>
<p>3、使用<strong>步骤 2</strong>&nbsp;的方法时,命令输出将不再打印到 CMD 窗口中,如果想同时在屏幕中打印出来,可以使用以下命令:</p>
<div class="jb51code"><pre class="brush:xhtml;">command &gt; D:\output.txt | type D:\output.txt</pre></div>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202508/202508141113081002.jpg" /></p>
<h3>将PowerShell命令输出保存到文本文件</h3>
<p>要将 PowerShell 命令执行结果保存到文本文件,请使用以下步骤:</p>
<p>1、使用&nbsp;Windows + X&nbsp;快捷键打开快捷菜单&mdash;&mdash;选择 Windows PowerShell(管理员)</p>
<p>2、执行以下命令以将输出保存到文本文件:</p>
<div class="jb51code"><pre class="brush:xhtml;">command | Out-File -FilePath D:\output.txt</pre></div>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202508/202508141113081003.jpg" /></p>
<p>上述示例中&nbsp;command&nbsp;代表您所执行的命令,&nbsp;D:\output.txt&nbsp;表示要输出到的文本文件路径。</p>
<p>3、我们可以通过以下命令在屏幕上打印出上述命令保存到文本文件中的内容:</p>
<div class="jb51code"><pre class="brush:xhtml;">Get-Content -Path D:\output.txt</pre></div>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202508/202508141113081004.jpg" /></p>
<p>最后说明一下,本文所介绍的内容同时适用于 Windows 7/8/10 及更新版本的微软操作系统。</p>
<blockquote><p><strong>推荐阅读:</strong><a href="https://www.jb51.net/os/windows/958773.html" target="_blank">windows为什么有两个命令行工具? PowerShell VS 命令提示符区别对比</a></p></blockquote>
頁: [1]
查看完整版本: win10怎么将命令提示符或PowerShell命令输出保存到txt文本文件?