用于写入打印机名称的 PowerShell 脚本

Rob*_*ert 1 windows powershell

我有一个 PowerShell 脚本。这:

Get-Printer | ft name,portname,location | Export-Csv c:\intel\intvprint2.csv -NoTypeInformation
Run Code Online (Sandbox Code Playgroud)

但这没有任何好处:(我制作了脚本,但结果是文件错误数据。

这使得:

"ClassId2e4f51ef21dd47e99d3c952918aff9cd","pageHeaderEntry","pageFooterEntry","autosizeInfo","shapeInfo","groupingEntry"
"033ecb2bc07a4d43b5ef94ed5a35d280",,,,"Microsoft.PowerShell.Commands.Internal.Format.TableHeaderInfo",
"9e210fe47d09416682b841769c78b8a3",,,,,
"27c87ef9bbda4f709f6b4002fa4af63c",,,,,
Run Code Online (Sandbox Code Playgroud)

但现在看到这个:

Get-Printer | ft name,portname,location

name                          portname               location
----                          --------               --------
9620HP2055DN                  172.17.252.130         loc1
9590HP2055DN                  172.17.239.45          loc2
Run Code Online (Sandbox Code Playgroud)

为什么剧本不好?

Ger*_*der 5

ft是 的别名Format-Table,旨在在终端中漂亮地输出数据。您想使用Select-Object(别名select ) 代替。

Get-Printer | select name,portname,location | Export-Csv c:\intel\intvprint2.csv -NoTypeInformation
Run Code Online (Sandbox Code Playgroud)