Welcome

首页 / 编程脚本 / Windows Powershell 管道和重定向

管道
把上一条命令的输出作为下一条命令的输入。
PowerShell管道
PowerShell管道
例如通过ls获取当前目录的所有文件信息,然后通过Sort -Descending对文件信息按照Name降序排列,最后将排序好的文件的Name和Mode格式化成Table输出。
PS C:PStest> ls | sort -Descending Name | Format-Table Name,ModeNameMode--------d.txt-a---c.txt-a---b.txt-a---ABC d----a.txt-a---
重定向
把命令的输出保存到文件中,‘>"为覆盖,">>"追加。
PS C:PStest> "Powershell Routing" >test.txtPS C:PStest> Get-Content .	est.txtPowershell RoutingPS C:PStest> "Powershell Routing" >>test.txtPS C:PStest> "Powershell Routing" >>test.txtPS C:PStest> "Powershell Routing" >>test.txtPS C:PStest> "Powershell Routing" >>test.txtPS C:PStest> "Powershell Routing" >>test.txtPS C:PStest> Get-Content .	est.txtPowershell RoutingPowershell RoutingPowershell RoutingPowershell RoutingPowershell RoutingPowershell RoutingPS C:PStest>