VMware Cloud Community
MayuriJ87
Contributor
Contributor

Getting VsphereVM name

Is there any better way to get the vsphereVM name. I am following the below approach,

    $vmrdweb = Get-vspherevmname -vmname $Rdwebname -org $NewOrg.Name -vapp $vapp.Name -CIServer $global:DefaultCIServers.Name -CISessionId $global:DefaultCIServers.sessionid -VIserver $global:DefaultVIServer.Name -VIsessionid $global:DefaultVIServer.SessionId

Inside the Get-vspherevmname function , I have written below block of code,

      Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -Confirm:$false | Out-Null

         

            $ciconnect = Connect-CIServer -Server $ciserver -Session $cisessionid

           

           do { $vma = Get-CIVM -Org $org -VApp $vapp -Name $vmname

           Start-Sleep -Seconds $3Seconds   

            $vmconf = $vma.ExtensionData           

            $vmtype = $vma.ExtensionData.Type

            $vma = Get-CIVM -Org $org -VApp $vapp -Name $vmname

            Start-Sleep -Seconds $5Seconds

            $vmConfUri = $vma.ExtensionData.Href

            $webclient = New-Object system.net.webclient -ErrorAction stop

            $webclient.Headers.Add('x-vcloud-authorization',$vmConf.Client.SessionKey)

            Start-Sleep -Seconds $3Seconds

            $webclient.Headers.Add('accept',$vmType + ";version=$($APIVersion)")

            Start-Sleep -Seconds 15

            [xml]$vmConfXML = $webclient.DownloadString($vmConfUri)

This approach seems to be failing as it takes longer in generating Uri and it fails to extract the vm name. Is there any better approach ?

0 Kudos
2 Replies
scott28tt
VMware Employee
VMware Employee

Moderator: Moved to PowerCLI


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
0 Kudos
LucD
Leadership
Leadership

Doesn't the following return the vSphere VM name?

Get-CIVM  -Org $org -VApp $vapp -Name $vmname |

Get-VM |

Select -ExpandProperty Name


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

0 Kudos