Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Find over 1000 vm servers in 40 vCenters project

$
0
0

I got assigned a task to find over 1000 vm servers vCenter. I have about 40 vCenters to search for each vm. Anyone have any suggestions on who's the best way to go about it?

 

1. I have a .csv file with each vm server name and every vCenter I have to search

2.Do I login to every vCenter then start searching for every vm?

3. Do I login to 1 vCenter at a time then search for each server?

4. Do put the vCenters and server names in a hash table?

 

I'm not sure where I should start Anyone have a script that will do something like what I'm looking to do?

So, I started the script and I can get connected to multiple vCenters but not sure what the best way is  to look for the vm.

The other thing is I'm not sure is how to output what I find to a .csv file

############### Script ###############

#Plug-ins
if(-not (Get-PSSnapin VMware.VimAutomation.Core))
{
   Add-PSSnapin VMware.VimAutomation.Core
}

Set-PowerCLIConfiguration -DefaultVIServerMode multiple -Confirm:$false
$MyCredentials = IMPORT-CLIXML C:\temp\SecureCredentials.xml

$VMSearch = Import-Csv "C:\temp\vmsearch.csv" -Header ("ServerName","VIServer")
$ServerName = $VMSearch | % { $_."ServerName" }
$VIServer  = $VMSearch | % { $_.VIServer }

Foreach ($vCenter in $VIServer){

    #Connects to the vCenter
    connect-viserver -Server $vCenter -Credential $MyCredentials
   
            Foreach ($ServerName in $vCenter){
                $getVM = get-vm | where {$_.Name -eq $ServerName}
            }
    #$getVM
   
#Disconnect-VIServer
}


Viewing all articles
Browse latest Browse all 6937

Trending Articles