将控制台输出写入文件 - 文件意外为空 [英] Writing console output to a file - file is unexpectedly empty

查看:29
本文介绍了将控制台输出写入文件 - 文件意外为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不熟悉脚本,我正在尝试将返回的有关 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

我能够连接到虚拟机,检索硬盘信息并在控制台中查看它.该文件是在我想要的地方创建的,并且命名正确.没有数据被放入文件中.我已经尝试过 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

这篇关于将控制台输出写入文件 - 文件意外为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆