VMware Cloud Community
crosen
Contributor
Contributor
Jump to solution

Failing to get UUID

This worked until recently and I do not believe anything has changed.  Now nothing is returning for the UUID.  Thanks.

$report = @()
    foreach($vm in Get-VM){
        $guest = Get-VMGuest -VM $vm   
        $row = "" | Select UUID,VMName

        $row.UUID = $vm.ExtensionData.config.uuid

     $row.VMName = $vm.Name

     $report += $row   
    }
    $report | Export-Csv "$filename1" -NoTypeInformation -UseCulture
    Disconnect-VIServer -Confirm:$False

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That PowerCLI version quite old, you could consider upgrading to 5.0.1

Since you apparently use the $guest variable later on in the script, the bold line has to stay.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Still works for me.

Which versions (vSPhere & PowerCLI) are you using ?

Btw why is the Get-VMGuest in there, that is not needed.

$report = @()
foreach($vm in Get-VM  ){
  $row = "" | Select UUID,VMName
  $row.UUID = $vm.ExtensionData.config.uuid
 
$row.VMName = $vm.Name
 
$report += $row } $report


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
greenpride32
Enthusiast
Enthusiast
Jump to solution

I'm not sure if I follow everything in your code exactly, but you can access the extensiondata directly from your get-vm object to make it much simpler.

get-vm | foreach {$_.name,$_.extensiondata.config.uuid}

Looks like LUCD beat me to the punch.

0 Kudos
crosen
Contributor
Contributor
Jump to solution

CLI is 4.0.1.2164

vSphere is 4.1 and 5.0

Here is my full function and I'm actually trying to pull a lot of data.  I have the blanks in there because I pull them in other scripts and then parse it together using Perl.  I don't know why it is in there, but I can drop that bold line?

function vCell01Data {
    $filename1 = 'C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Notes_Fields\TCOMDB_Data\vcell01_consolidated_tcomdb1.csv'
    write-host ("Working on VM data for $VIServer....")
    $VIServer = "rtpvcell70"
    connect-viserver -server $VIServer -user $User -password $Password
    $report = @()
    foreach($vm in Get-VM){
        $guest = Get-VMGuest -VM $vm   
        $row = "" | Select UUID,VMName,Notes,vCenter,IPAddr,Owner1,Owner2,VP,OSFullName,Product,Resourcepool,TotalMemory,TotalCPU,DisksGB,ToolsStatus,VMState,Datastore,NumSnaps,SizeSnaps,One,Two,Three,DOB,EXP,Six,Seven,Eight,Nine,Ten,Eleven,Twelve,Thirteen

        $row.UUID = $vm.ExtensionData.config.uuid
        $row.VMName = $vm.Name

        #$row.Notes = $VM.Description
        $notesfield = $VM.Description
        $row.Notes = ($notesfield -replace ",",";")

        $row.vCenter = $VIServer
        $row.IPAddr = $guest.IPAddress[0]
        $row.Owner1 = ""
        $row.Owner2 = ""
        $row.Product = ""

        $OS = $vm.Guest.OSFullName
        $row.OSFullName = ($OS -replace ",","")

        $repo = (Get-ResourcePool -VM $vm).Name
        $row.Resourcepool = ($repo -replace ",","")

        $row.TotalMemory = $vm.memorymb
        $row.TotalCPU = $vm.numcpu
        $row.DisksGB = [Math]::Round((($VM.HardDisks | Measure-Object -Property CapacityKB -Sum).Sum * 1KB / 1GB),2)
        $row.ToolsStatus = $vm.Extensiondata.Guest.toolsstatus
        $row.VMState = $vm.powerState

        $dstore = [string]::Join(',',(Get-Datastore -VM $vm | %{$_.Name}))
        $row.Datastore = ($dstore -replace ",",";")

        $row.NumSnaps = ""
        $row.SizeSnaps = ""
        $row.One = ""
        $row.Two = ""
        $row.Three = ""
        $row.DOB = ""
        $row.EXP = ""
        $row.Six = ""
        $row.Seven = ""
        $row.Eight = ""
        # Nine is the utilization metric:
        $row.Nine = ""
        $row.Ten = ""
        $row.Eleven = ""
        $row.Twelve = ""
        $row.Thirteen = ""
        #$row.Fourteen = ""
        $report += $row   
    }
    $report | Export-Csv "$filename1" -NoTypeInformation -UseCulture
    Disconnect-VIServer -Confirm:$False
}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That PowerCLI version quite old, you could consider upgrading to 5.0.1

Since you apparently use the $guest variable later on in the script, the bold line has to stay.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
crosen
Contributor
Contributor
Jump to solution

That did it....thanks guys!!!

0 Kudos
zXi_Gamer
Virtuoso
Virtuoso
Jump to solution

Looks like LUCD beat me to the punch.

I agree. LUCD has written a PowerCLI script to browse the communities, grep the questions and answer them automatically on the questions :smileysilly:

JFF :smileygrin:, he is the Lord Of The PCLI

0 Kudos