1 2 Previous Next 15 Replies Latest reply on May 15, 2019 6:39 AM by GordonPM

    Get-TagAssignment operation causes Disconnect-Viserver to hang

    GordonPM Novice

      Ourbackup software uses the tags we assing in vSphere to schedule backups/type. One drawback of this is that sometimes adding a VM to backups is forgotten


      I have written a small script using PS/PowrerCLI and windows Forms to list all the VMs, along with their backup tag.


      The script works perfectly, to connect, amd I can list VMs, however if I use Get-TagAssignment to query the tag detail any following operation to disconnect from vCenter causes the entire Windows Form to hang.


      Happy to provide the whole script if anyone wants to try and reporduce, as there's no sensitive info in it.


      As an example there are two values for the variable $BackupTag in the following snippet - the one that lists the VM name works fine and the code/Windows Form closes gracefully, but if I run the second, querying the Tags, the Form will hang when I try to disconnect from vCenter:





          $VcConnectText.AppendText("`r`nRetrieving VM list")

          $Script:AllVMs = Get-VM | Sort-Object Name

          $TotalVMs.Text = [int]$AllVMs.count


          $VcConnectText.AppendText("`r`nRetrieving VM tags")

      # Check if PoweredOff checkbox enabled

          If ($Script:ScanPoweredOff) {

              $Script:ScanVMList = $AllVMs


          Else {

              $Script:ScanVMList = $AllVMs | Where-Object {$_.PowerState -ne 'PoweredOff'}


      # Compile object data

           $NoTagText = "No Backup Tag"

           $ScanVMList | ForEach-Object {

      #     $BackupTag = $_.Name


           $BackupTag = ((Get-TagAssignment -Entity $_ ).Tag.Name).ToString() # | Where-Object {$_ -in $ValidTags.Name}







      # Detect if form is closing, if the form exit button hasn't been used, cancel the close and prompt so that we can disconnect cleanly from vCenter



          If ($script:CanClose -ne $true) {

          $VcConnectText.AppendText("`r`nPlease use Exit button to disconnect from vCenter and close the application")

          $_.Cancel = $true



      # Exit and close form





          Try {

              Disconnect-VIServer -Server * -Force -Confirm:$false -ErrorAction Stop


          Catch {


          $script:CanClose = $true



        1 2 Previous Next