2016-06-28 18 views
0

I VMを作成しました。そのプロパティをCSVファイルにエクスポートします。
私はIPAddress、SwitchName、Macaddressを私に与えませんでした。Powershell:VMプロパティの取得

$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アドレスはありますか?

誰かが私を助けることができれば素晴らしいだろう。

+0

を、たIPAddressは、IPv4アドレスとIPv6アドレスを持つ配列である - ので、これはHyperVの場合であるならば、 '$ vm.Guest.IPAddress [0]' – Avshalom

+0

エラーを試してみてください。 NULL-Arrayにインデックスを追加することは不可能です! – frhling1

+0

'$ VM.IPAddresses'を実行して結果を表示します – Avshalom

答えて

0

はこれを試してみてください:VMware社の

$Data = @() 

$VMs = "Server-001","Server-002","Server-003" 

foreach($VM in $VMs) 
{ 
    $VMInfo = Get-VM -Name $VM 
    $VMNetwork = $VMInfo | Get-VMNetworkAdapter 

    $VMCustom = New-Object System.Object 
    $VMCustom | Add-Member -Type NoteProperty -Name VMName -Value $VMInfo.VMName 
    $VMCustom | Add-Member -Type NoteProperty -Name Status -Value $VMInfo.Status 
    $VMCustom | Add-Member -Type NoteProperty -Name Generation -Value $VMInfo.Generation 

    $VMCustom | Add-Member -Type NoteProperty -Name IPAddress -Value $VMNetwork.IPAddresses[0] 
    $VMCustom | Add-Member -Type NoteProperty -Name MacAddress -Value $VMNetwork.MacAddress 
    $VMCustom | Add-Member -Type NoteProperty -Name SwitchName -Value $VMNetwork.SwitchName 

    $Data += $VMCustom 
} 

$Data | Export-CSV "C:\VM.csv" -Delimiter ";" -NoTypeInformation 
+0

ありがとう。まだ空いているIPaddress以外はすべて動作します。 IPが静的か動的かは関係ありませんか? IPが静的か動的かをチェックする列を追加することは可能ですか? – frhling1

+0

これを実行すると、何も返されますか?$ VMInfo = Get-VM -Name "Server-001"; $ VMNetwork = $ VMInfo | Get-VMNetworkAdapter; $ VMNetwork.IPAddresses – Oggew

+0

これは興味深いです。昨日から今日までは何も変えていませんが、今日はIPアドレスを示しています。すばらしいです。ありがとう。 – frhling1

関連する問題