PowerCLI

 View Only
  • 1.  Powershell script not getting information from tags - vCenter Server linked mode.

    Posted Sep 30, 2025 05:31 AM

    Since we upgraded our VI from vCenter Server 7.0.3 to v8.0.3 our Powershell scripts no longer get information from tags from the linked vCenter Servers.

    The scenario is:

    We have a vCenter Server called Wiltshire that has a cluster called Swindon.

    We have another vCenter called Hampshire that has a cluster called Andover.

    The 2 vCenter Servers are connected using Linked Mode with the Wiltshire vCenter Server being both the SSO and PSC.

    There is a Tag Category called "Location" and hosts in the Swindon cluster are tagged "Swindon" and the hosts in the Andover cluster are tagged "Andover".

    When I run the script, it connects to both vCenter Servers and outputs to a .CSV file with the results.

    The files contains the name of each host. The location field is populated with the location tag for the hosts in the Swindon cluster but not the hosts in the Andover cluster.

    Here's my scripts:

    connect-viserver -server wiltshire.mynetwork.co.uk -user myuseraccount -Password mypassword -AllLinked

    $hosts = Get-VMHost

    $Output = foreach ($vmhost in $hosts){

    Get-VMHost $vmhost | select Name, 

    @{N="Location";E={((Get-TagAssignment -Entity $_ -Category Location | select -ExpandProperty Tag).Name )}} 

    }

     $Output | Export-Csv W:\VMware\Capacity-Reports\All-Host-details.csv -NoTypeInformation

    'myuseraccount' is a local administrators on both vCenter Servers.


    Here's the output:

    Name                                          Location
    swindon1.mynetwork.co.uk       Swindon
    swindon2.mynetwork.co.uk      Swindon
    swindon3.mynetwork.co.uk      Swindon
    andover1.mynetwork.co.uk
    andover2.mynetwork.co.uk
    andover3.mynetwork.co.uk

    Does anyone have any idea why this has started happening ???



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


  • 2.  RE: Powershell script not getting information from tags - vCenter Server linked mode.

    Posted Oct 01, 2025 01:38 AM

    Hi Rob, 

    did you try "andover" alone? Do you get any output from there? 


    Hint:

    Never use password as plain text in scripts. Use get-credential instead and save the credential for later usage. 

    Save credential: 

    $credential = get-credential
    $credential | export-clixml -Path "path\to\your\credential.xml"

    Usage: 

    $credential = import-clixml-Path "path\to\your\credential.xml"
    connect-viserver yourVIServer -credential $credential

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



  • 3.  RE: Powershell script not getting information from tags - vCenter Server linked mode.

    Posted Oct 01, 2025 02:47 PM

    Hi rkabelich,

    Thanks for responding... Yes I've tried the vCenter Servers individually but no luck.

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