我創建了一個虛擬機,我想將其屬性導出爲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