Quantcast
Channel: Spiceworks Community - Latest topics
Viewing all articles
Browse latest Browse all 184196

Powershell script to place multiple entries in one csv part of a foreach loop

$
0
0

Hi Folks,

I am writing a script to extrapolate a number of specific Hyper-V VM queries on the SCVMM. Part of my script is to obtain all IP addresses from a VM. This is my script:

Powershell
$Data=@()$VMs="SOMEVM"foreach($VMin$VMs){$VMInfo=Get-VM-Name$VM$VMNetwork=$VMInfo|Get-VMNetworkAdapter$VMCustom=New-ObjectSystem.Object$VMCustom|Add-Member-TypeNoteProperty-NameIPAddresses-Value$VMNetwork.IPAddresses[0]$Data+=$VMCustom}$Data|Export-CSV"C:\output.csv"-Delimiter","-NoTypeInformation

When I run the script, I get the following:

"IPAddresses"
"10.10.x.x"

...which is fine and dandy, apart from the fact that when I run the command manually, the VM actually has more than one IP address:

Get-VM -Name SOMEVM | Get-VMNetworkAdapter

I get the following output:

Name IsManagementOs VMName SwitchName ...


Viewing all articles
Browse latest Browse all 184196

Trending Articles