将命令(即输入不输出)写入文件
问题描述:
Out-File允许我们将输出写入文件。如果我们想要将输入写入文件会怎么样?将命令(即输入不输出)写入文件
我想要在PowerShell会话期间编写的所有命令的列表。该文件应该是这样的:
dir
cd
ni myFile.txt -t file
cd..
我们想跟踪我们在PowerShell中使用的命令。
答
试试这个:
Get-History |
select -ExpandProperty commandline |
Add-Content commandhistory.txt
答
你可以利用Start-Transcript
和Stop-Transcript
有关每个命令的Technet链接:start-transcript和stop-transcript
用例:Start-Transcript -Path C:\Folder\Transcript.txt