Carl Webster Accessibility Statement

Carl Webster is committed to facilitating the accessibility and usability of its website, carlwebster.com, for everyone. Carl Webster aims to comply with all applicable standards, including the World Wide Web Consortium’s Web Content Accessibility Guidelines 2.0 up to Level AA (WCAG 2.0 AA). Carl Webster is proud of the efforts that we have completed and that are in-progress to ensure that our website is accessible to everyone.

If you experience any difficulty in accessing any part of this website, please feel free to email us at info@carlwebster.com and we will work with you to provide the information or service you seek through an alternate communication method that is accessible for you consistent with applicable law (for example, through telephone support).

  • New PowerShell Script: Remove-HostingConnection V1.0

    You have moved to a new/updated/upgraded hypervisor or added new/updated/upgraded storage. Then you go to delete either the entire old hosting connection or just an old resource connection and received the dreaded popup:

    “There is currently an active background action”

    ARGH!!! What to do?

    Previously, I wrote about my issues with removing a hosting connection because of a mysterious active background task. In that article, I stated, “If this were a common occurrence, I would write a script to do all this…”.  Much to my dismay, this has become a common occurrence with you and your customers. It was time to create a script to automate this tedious process.

    This is the first script I am creating that makes changes to a XenDesktop Site. Because of this, I try to do as much error checking as possible and stop the script from running if I find anything even slightly wrong.  There are several places where I have code similar to:

    If(Some Condition)
    {
         #we should never get here
         Write-Host "Unable to <do some process>. You shouldn't be here! Script will close."
         Write-Host "If you get this message, please email webster@carlwebster.com" -ForegroundColor Red
         $error
         Exit
    }
    

    If there are no active tasks for the hosting connection selected,  then NOTHING is removed from the Site. The script will state there were no active tasks found and end.

    Here are examples of hosting and resource connections and the script in action.

    Figure 1
    Figure 1
    Figure 2
    Figure 2
    Figure 3
    Figure 3
    Figure 4
    Figure 4
    Figure 5
    Figure 5
    Figure 6
    Figure 6
    Figure 7
    Figure 7
    Figure 8
    Figure 8
    Figure 9
    Figure 9
    Figure 10
    Figure 10
    Figure 11
    Figure 11
    Figure 12
    Figure 12
    Figure 13
    Figure 13

    I also added support for -WhatIf and -Confirm thanks to the clear and simple articles from Adam Bertram.

    This will allow you to be safe and verify the script’s actions.

    Figure 14
    Figure 14

    You can always find the most current script by going to https://www.carlwebster.com/where-to-get-copies-of-the-documentation-scripts/

    Thanks

    Webster







    About Carl Webster

    Webster is a Sr. Solutions Architect for Choice Solutions, LLC and specializes in Citrix, Active Directory and Technical Documentation. Webster has been working with Citrix products for many years starting with Multi-User OS/2 in 1990.

    View all posts by Carl Webster

    5 Responses to “New PowerShell Script: Remove-HostingConnection V1.0”

    1. Jonathan Redford Says:

      Ok… I have a pesky controller in my environment that won’t let go of Nutanix after I upgraded the hypervisor. I’ve removed the machine catalogs and there are still 13 background jobs pending. Now, I have looked into clearing these jobs, but there are a lot to sift through. Like over 10000 kind of a lot. Your script cannot handle that too easily apparently. I am not sure what needs to be changed with the script so I figured I would nudge you and see if you’ve heard of this one before. Code looks pretty tight, btw.

      Reply

      • Carl Webster Says:

        I have not heard of that before and without having access to your system, I don’t know what you need to do to resolve it. Are you able to open a support ticket with either Nutanix or Citrix? I have a few friends who work at Nutanix. I will see if they have any suggestions.

        Thanks

        Webster

        Reply

    2. Andrew Williamson Says:

      Nice script Carl – can’t test it, but I think I spotted a slight logic flaw?

      Your ShouldProcess will rightly only operate if -WhatIf isn’t provided – but it looks like you’re going to write fails to your log if you supply WhatIf. Which isn’t really a fail – you just didn’t carry out the action, in which case no point in logging?

      If I’m reading it right, here’s a typical sample with line numbers where I think the issue is:

      552: Set Succeeded = false
      555: Start the highlevel log action with Start-LogHighLevelOperation
      563: remove-item with whatif…
      569: and if that worked, succeeded = true
      But we passed -whatif, so succeeded = false – for something we never tried to do
      583: close and write a log for that fail

      Would suggest perhaps wrapping the logging elements as well in the ShouldProcess blocks. Otherwise, every time you pass WhatIf (testing etc), you’ll be logging fails all over the place.

      Reply

      • Carl Webster Says:

        When I get back home and to my lab, I will re-test that scenario. Thanks for looking at the script.

        Webster

        Reply

      • Carl Webster Says:

        I found the logic issue you reported. Thanks for finding the bug. I have submitted the fix to my PowerShell mentor for his feedback. It appears to work for me. If you would like to test the fix, just send me an email. webster@carlwebster.com

        Thanks

        Webster

        Reply

    Leave a Reply