PS> '[ Man, it works! ]' -replace '\s{2,}', ' '
[ Man, it works! ]
你也可以用这个方法转换成固定格式的CSV表格:
PS> (qprocess) -replace '\s{2,}', ','
>tobias,console,1,3876,taskhostex.exe
>tobias,console,1,3844,explorer.exe
>tobias,console,1,4292,tabtip.exe
一旦变成CSV格式,你就可以使用ConvertFrom-Csv获取该文本数据的对象:
PS> (qprocess) -replace '\s{2,}', ',' | ConvertFrom-Csv -Header Name, Session, ID, Pid, Process
Name : >tobias
Session : console
ID : 1
Pid : 3876
Process : taskhostex.exe
Name : >tobias
Session : console
ID : 1
Pid : 3844
Process : explorer.exe
Name : >tobias
Session : console
ID : 1
Pid : 4292
Process : tabtip.exe
(...)
支持所有PS版本
您可能感兴趣的文章:
- Powershell小技巧之查询AD用户
- Powershell小技巧之等待输入一个按键
- Powershell小技巧之轻松从网上下载文件
- PowerShell小技巧之实现文件下载(类wget)
- Powershell小技巧之开启关闭远程连接
- PowerShell使用小技巧分享
声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论(0)