none
Powershell script to extract specific VM info from Hyper-V SCVMM RRS feed

  • Question

  • Hi Folks,

    Looking for some guidance here, here is my script:

    $Data = @()

    $VMs = "SOMEVM"


    foreach($VM in $VMs)
    {
        $VMInfo = Get-VM -Name $VM
        $VMNetwork = $VMInfo | Get-VMNetworkAdapter
        $VMVHD = $VMInfo | Get-VMHardDiskDrive | Get-VHD
        $VMHOST = $VMInfo | Get-VMHost
        $VMWMI = Get-WmiObject Win32_OperatingSystem -ComputerName $VM
        $VMWMIPROD = Get-WmiObject Win32_Product -ComputerName $VM
        $VMWMIPRODLOGDSK = Get-WmiObject win32_logicaldisk -ComputerName $VM
        $VMWMIPROC = Get-WMIObject Win32_Processor -ComputerName $VM
        $VMWMISVRUUID = $VMInfo | Get-WmiObject Win32_ComputerSystemProduct

        $VMCustom = New-Object System.Object
        

        ##Add Application - NEED TO ITERATE OVER LIST
        $VMCustom | Add-Member -Type NoteProperty -Name Applications1 -Value $VMWMIPROD.name
        

        ##VM Name
        $VMCustom | Add-Member -Type NoteProperty -Name VMName -Value $VMInfo.VMName
        ##IP addresses (ipv4/ipv6) - NEED TO ITERATE OVER LIST
        $VMCustom | Add-Member -Type NoteProperty -Name IPAddresses -Value $VMNetwork.IPAddresses[0]
        ##VMid (UUID)
        $VMCustom | Add-Member -Type NoteProperty -Name VMid -Value $VMinfo.id
        ##VM CPUs assigned
        $VMCustom | Add-Member -Type NoteProperty -Name ProcessorCount -Value $VMinfo.ProcessorCount
        ##VM Memory assigned
        $VMCustom | Add-Member -Type NoteProperty -Name MemoryAssigned -Value $VMinfo.MemoryAssigned
        ##VM Virtual HD size
        $VMCustom | Add-Member -Type NoteProperty -Name VMHDsize -Value $VMVHD.size[0]
        ##VM Used Filesize
        $VMCustom | Add-Member -Type NoteProperty -Name VMUsedHDSize -Value $VMVHD.filesize[0]
        ##VM OS Version - in Decimal
        $VMCustom | Add-Member -Type NoteProperty -Name OSVersion -Value $VMWMI.Version
        ##VM Uptime
        $VMCustom | Add-Member -Type NoteProperty -Name Uptime -Value $VMinfo.Uptime
        ##VM Cluster Info (if clustered)
        $VMCustom | Add-Member -Type NoteProperty -Name ClusterName -Value $VMinfo.cluster
        ##Hyper-V Hostname that VM resides on
        $VMCustom | Add-Member -Type NoteProperty -Name Hyper-v-ComputerName -Value $VMinfo.ComputerName
        ##Total Hyper-v Host Memory
        $VMCustom | Add-Member -Type NoteProperty -Name TotalMemoryCapacity -Value $VMHOST.MemoryCapacity
        ##Hyper-V Host Provisioned Disk Space for VM
        $VMCustom | Add-Member -Type NoteProperty -Name DriveLetter -Value $VMWMIPRODLOGDSK.DeviceID[0]
        $VMCustom | Add-Member -Type NoteProperty -Name Freespace -Value $VMWMIPRODLOGDSK.FreeSpace[0]
        $VMCustom | Add-Member -Type NoteProperty -Name HostProvSize -Value $VMWMIPRODLOGDSK.Size[0]
        ##VM Power State (running/not running)
        $VMCustom | Add-Member -Type NoteProperty -Name PoweredState -Value $VMinfo.State
        ##Host UUID
        $VMCustom | Add-Member -Type NoteProperty -Name HOSTUUID -Value $VMWMISVRUUID.UUID
        ##Logical Hyper-V Host Processor Count
        $VMCustom | Add-Member -Type NoteProperty -Name LogicalProcessorCount -Value $VMHOST.LogicalProcessorCount
        ##VM Load in Percentage
        $VMCustom | Add-Member -Type NoteProperty -Name CPULoadPercentage -Value $VMWMIPROC.LoadPercentage[0]
        ##VM Created on Time/Date
        $VMCustom | Add-Member -Type NoteProperty -Name CreationTime -Value $VMinfo.CreationTime


        $Data += $VMCustom


    $Data | Export-CSV "C:\output.csv" -Delimiter "," -NoTypeInformation

    My first issue is that when the line"$VMCustom | Add-Member -Type NoteProperty -Name IPAddresses -Value $VMNetwork.IPAddresses[0]" is run, I only get the first IP address listed for that VM. How do I get the read IP addresses to be added to the end of this string in my array?

    Any help greatly appreciated!

    • Moved by Bill_Stewart Monday, December 17, 2018 6:39 PM This is not "debug/fix/rewrite my script for me" forum
    Thursday, October 4, 2018 10:13 PM