I created a script to list out cluster details and I thought I would make it faster by using get-view instead of Get command for every object. I ran into a problem on line 14. It seems I have datacenters in different virtual centers with the same .MoRef vaules. Not sure how I can script around that.
Note this script below is a stripped down version of the overall script
$csvreport = @()
$ClusterList=@()
$OutputFile="C:\Temp\looptesting.csv"
$Date=Get-Date -Format d
foreach ($virtualcenter in $DefaultVIServers) {
ForEach ($DC in (Get-View -ViewType Datacenter -Server $virtualcenter)){
Foreach ($cluster in (Get-View -ViewType ClusterComputeResource -SearchRoot $DC.MoRef)){
$ClusterList = "" |select-object "Collection Date","Virtual Center",DataCenter,Cluster
$ClusterList."Collection Date"=$Date
$ClusterList."Virtual Center"=$virtualcenter
$ClusterList.DataCenter=$DC.Name
$ClusterList.Cluster=$cluster.Name
$csvreport += $ClusterList
}
}
}
$csvreport |export-csv -NoTypeinformation $OutputFile
Can't you just use the Server parameter on line 14, as you did on line 12 ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It seems I have datacenters in different virtual centers with the same .MoRef vaules. Not sure how I can script around that.
Extract from a post from William Lam.
A Managed Object Reference ID also known just as MoRef ID is a unique value that is generated by the vCenter Server and is guaranteed to be unique for a given entity in a single vCenter instance.
So your guess seems to be correct.
We are in the same boat regarding working with multiples vCenter servers.
The solution i am using at a high level is:
A file containing the list of all vCenter name.
Import the list with import-csv
For each vCenter
Connect to this vcenter
Extract data needed and store them in a variable like $DataForThisVcenter
$FinalResult = $FinalResult + $DataForThisVcenter
Disconnect from this vcenter
And finally export the $FinalResult
It is not perfect but at least there are no conflicts with identical moref.
If you need it, i can provide example.
Can't you just use the Server parameter on line 14, as you did on line 12 ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That was my 1st thought but I wanted to be logged into all the vcenters so that any errors connecting to vcenters could be handled up front. My fear is that the script will run for 2 hours and then fails connecting to the last vcenter and then I will have to start all over.
I started typing a response that was no I can't replace -searchroot with - server. I then realized you meant use them both :smileylaugh:. And it worked
Foreach ($cluster in (Get-view -ViewType ClusterComputeResource -Server $virtualcenter -Searchroot $DC.moref)){ |