我有以下powershell脚本
$MyVM= [XML] @"
<VM>
<IPAddress>X.Y.Z.T</IPAddress>
<VMName>R2-VM</VMName>
<Vsphere-host>X.X.X.X</Vsphere-host>
<OS>W2K8-R2</OS>
<AssignedTo>Tester</AssignedTo>
</VM>
"@
Write-host " Your VM details"
Write-host "------------------"
Write-host "IPaddress: " $MyVM.VM.IPAddress
Write-host "Host Machine IP:" $MyVM.VM.Vsphere-host
它不是显示Vsphere主机信息,而是显示如下
Host Machine IP: System.Xml.XmlDocument.VM.Vsphere-host
如何让它发挥作用?
答案 0 :(得分:4)
将Vsphere-host
放在引号之间,如下所示:"Vsphere-host"
$MyVM= [XML] @"
<VM>
<IPAddress>X.Y.Z.T</IPAddress>
<VMName>R2-VM</VMName>
<Vsphere-host>X.X.X.X</Vsphere-host>
<OS>W2K8-R2</OS>
<AssignedTo>Tester</AssignedTo>
</VM>
"@
Write-host " Your VM details"
Write-host "------------------"
Write-host "IPaddress: " $MyVM.VM.IPAddress
Write-host "Host Machine IP:" $MyVM.VM."Vsphere-host"