Automation

 View Only
  • 1.  Dealing w linked vcenters

    Posted Nov 09, 2023 04:14 PM

    I think I've asked this question before, but can't seem to find if there was ever a good solution.

    Environment has ~40 vcenters. Some are linked, some are not.

    I'm running a modified version of Alan and Luc's role/permission script from 2010.  (yes, its still useful today!)

    The problem is that when I log into a linked vcenter, it creates a role from each vcenter login. So I end up getting duplicate roles. When you later go to set permissions using 'the role', it fails because there's two.

    So, the larger question is wondering if there is any way to tell that you're logged into a linked vcenter so that automation like this doesn't happen twice? Or is the only real solution to do a duplication check before role creation/whatever else you're trying to do?



  • 2.  RE: Dealing w linked vcenters

    Posted Nov 09, 2023 04:45 PM

    Or is there nothing more to do than:

    $TestForRole = get-virole | where {$_.Name -eq $vInventory.SelectNodes($XpathRoles).Name}
    if ($TestForRole){
         #create role
         }
    else {
         echo "Skipping $($vInventory.SelectNodes($XpathRoles).Name) because there was a duplicate in $vc}
         }
     


  • 3.  RE: Dealing w linked vcenters

    Posted Nov 09, 2023 05:46 PM

    Did you already try the Server parameter, pointing to one specific vCenter, on the New-VIRole cmdlet?



  • 4.  RE: Dealing w linked vcenters

    Posted Nov 09, 2023 05:50 PM

    Yes, the server parameter was unhelpful to separate roles in linked vcenters. Because the one role is shared across the linkage. So creating a second one from the second server creates a second role, same name but unique ID, shared across the linkage.

    Since I can't see any attribute that defines if linked or not, I think the only way is to check every time.



  • 5.  RE: Dealing w linked vcenters
    Best Answer

    Posted Nov 09, 2023 05:56 PM

    Afaik there is no property indicating if an object was created due to linked vCenters.
    That only plays when the object is created I suspect.

    So yes, testing, like your snippet, might be the best solution.



  • 6.  RE: Dealing w linked vcenters

    Posted Nov 09, 2023 06:00 PM

    Appreciate it.  And just realized my snippet was missing a "!" in the if test...