问题描述
我是脚本新手,我正尝试将有关VM的返回信息写入文本文件.我的脚本如下:
I'm new to scripting and I am trying to write the information returned about a VM to a text file. My script looks like this:
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无法将数据从数组移至字符串.我是否需要创建一个变量来保存返回的数据并从那里写入文件?
I am able to connect to the VM, retrieve the HDD info and see it in the console. The file is created where I want it and is correctly named. No data is ever put into the file. I have tried Tee-Object with the same results. I've also tried the -append switch. I did see a post about the data being returned as an array and Powershell is not able to move the data from an array to a string. Do I need to create a variable to hold the returned data and write to file from there?
谢谢
推荐答案
尝试一下:
Get-VM xxxxx |
Get-HardDisk |
Select Parent, Name, Filename, DiskType, Persistence |
Out-File -FilePath C:\Filepath
这篇关于将控制台输出写入文件-文件意外为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!