我创建了一个虚拟机,我想将其属性导出为CSV文件。
我所尝试的不会给我IPAddress,SwitchName,Macaddress。Powershell:获取虚拟机属性
$Data = @();
$VMs = Get-VM $VMName;
foreach($VM in $VMs){
$VMCustom = New-Object System.Object;
$VMCustom | Add-Member -Type NoteProperty -Name VMName -Value $VM.VMName;
# Get-VMNetworkAdapter -VMName $VMName | Select -expand IPAddresses
$VMCustom | Add-Member -Type NoteProperty -Name IPAddress -Value $VM.guest.IPAddresses;
$VMCustom | Add-Member -Type NoteProperty -Name SwitchName -Value $VM.MacAddress;
$VMCustom | Add-Member -Type NoteProperty -Name Status -Value $VM.State;
$VMCustom | Add-Member -Type NoteProperty -Name Generation -Value $VM.Generation;
$VMCustom | Add-Member -Type NoteProperty -Name SwitchName -Value $VM.SwitchName;
$Data += $VMCustom;
}
$Data | Export-CSV "C:\VM.csv" -Delimiter ";";
问题:Ipaddress,VM的IP地址或Hyper-V的IP地址?
如果有人能帮助我,那将会很棒。
在VMware,ip地址是IPv4和IPv6的地址阵列 - 因此,如果这是Hyper-V的情况下,尝试'$ vm.Guest.IPAddress [0]' – Avshalom
错误:不可能在NULL数组上添加索引! – frhling1
执行$ VM.IPAddresses并显示结果 – Avshalom