VMware Cloud Community
ranjitcool
Hot Shot
Hot Shot
Jump to solution

Vcenter linked mode wont filter through the script

Hey Guys,

So I have a power cli script that will pull all vms that are not v7 version.

I have a vcenter vcenter0 which has more vcneters in linked mode.

vcenter0

   --- vcenter1

   --- vcenter2

and so on. Each vcenter has a bunch of vms in datacenters, but when I run the script and login into vcneter0 it doesnt not pull vms from other linked mode vcenters.

What am i doing wrong and how do i pull vms from all vcneters.

Please help

Thanks

RJ

Please award points if you find my answers helpful Thanks RJ Visit www.rjapproves.com
0 Kudos
1 Solution

Accepted Solutions
Hosted201110141
Enthusiast
Enthusiast
Jump to solution

I've never done PowerCLI on a linked VC system but this should get you what you're looking for:

$vCenters = @(vc01fqdn, vc02fqdn, vc03fqdn)
$Object = @()
for ($i=0;$i -lt $vCenters.length;$i++) {
    Connect-VIServer -Server $vCenters[$i] -User Blah -Password Blah
    foreach ($Datacenter in Get-Datacenter) {
        Get-VM -Location $Datacenter | %{
            if($_.version -ne "v7") {
                $Object += New-Object PSObject -Property @{
                     OS = $_.ExtensionData.Guest.GuestFullName          
                     Name = $_.Name
                     Datacenter = $Datacenter
                     vCenter = $vCenters[$i]

                }
            }
        }
    }
    Disconnect-VIServer -Server $vCenters[$i] -Force
}

View solution in original post

0 Kudos
2 Replies
Hosted201110141
Enthusiast
Enthusiast
Jump to solution

I've never done PowerCLI on a linked VC system but this should get you what you're looking for:

$vCenters = @(vc01fqdn, vc02fqdn, vc03fqdn)
$Object = @()
for ($i=0;$i -lt $vCenters.length;$i++) {
    Connect-VIServer -Server $vCenters[$i] -User Blah -Password Blah
    foreach ($Datacenter in Get-Datacenter) {
        Get-VM -Location $Datacenter | %{
            if($_.version -ne "v7") {
                $Object += New-Object PSObject -Property @{
                     OS = $_.ExtensionData.Guest.GuestFullName          
                     Name = $_.Name
                     Datacenter = $Datacenter
                     vCenter = $vCenters[$i]

                }
            }
        }
    }
    Disconnect-VIServer -Server $vCenters[$i] -Force
}

0 Kudos
ranjitcool
Hot Shot
Hot Shot
Jump to solution

Thanks Hosted, thats what I thought I had to do.

RJ

Please award points if you find my answers helpful Thanks RJ Visit www.rjapproves.com
0 Kudos