我是脚本编写的新手,我正在尝试将有关VM的返回信息写到文本文件中。我的脚本如下所示:
Connect-VIServer -Server 192.168.255.255 -Protocol https -User xxxx -Password XXXXXX
Get-VM -Name xxxxxx
Get-VM xxxxx | Get-HardDisk | Select Parent, Name, Filename, DiskType, Persistence | FT -AutoSize
Out-File -FilePath C:Filepath
我能够连接到VM,检索HDD信息并在控制台中看到它。该文件在我想要的位置创建并正确命名。文件中没有数据。我尝试过Tee-Object,结果相同。我也尝试了-append开关。我确实看到了有关将数据作为数组返回的文章,而Powershell无法将数据从数组移至字符串。我是否需要创建一个变量来保存返回的数据并从那里写入文件?
谢谢
最佳答案
试试这个:
Get-VM xxxxx |
Get-HardDisk |
Select Parent, Name, Filename, DiskType, Persistence |
Out-File -FilePath C:\Filepath