VMware Cloud Community
AlbertWT
Virtuoso
Virtuoso
Jump to solution

Script to get multiple VCenter information?

Hi All,

I need some help in modifying the below PowerCLi script so it can be executed against multiple Center server?

$VCenter = @('PRDVC01-VM','VC03-VA','VCenter-PROD01')

$AdminUser = 'DOMAIN\Administrator'

$Password = 'XXyyZZ!@#'

Get-VIServer -Server $VCenter -User $AdminUser -Password $Password | Select Name, Version, Build

Thank you in advance.

/* Please feel free to provide any comments or input you may have. */
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this

You really should stop using Get-VIServer, that cmdlet is very old and not used anymore since Connect-VIServer was introduced.

$VCenter = @('PRDVC01-VM', 'VC03-VA', 'VCenter-PROD01')

$AdminUser = 'DOMAIN\Administrator'

$Password = 'XXyyZZ!@#'


Connect-VIServer -Server $VCenter -User $AdminUser -Password $Password

foreach ($vc in $global:defaultviservers) {

    Get-VM -PipelineVariable vm |

    Get-Snapshot |

    Select-Object @{N = 'vCenter'; E = { $vc.Name } },

        @{N = 'vCenter Version'; E = { $vc.Version } },

        @{N = 'vCenter Build'; E = { $vc.Build } },

        @{N = 'VM'; E = { $_.VM.Name } },

        Name, Description, Created, SizeGB

}

Disconnect-VIServer -Server * -Confirm:$false -Force


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

6 Replies
LucD
Leadership
Leadership
Jump to solution

Not too sure what the question/problem is, besides that Get-VIServer is ancient and that you should use Connect-VIServer.

This works

$VCenter = @('PRDVC01-VM','VC03-VA','VCenter-PROD01')

$AdminUser = 'DOMAIN\Administrator'

$Password = 'XXyyZZ!@#'

Connect-VIServer -Server $VCenter -User $AdminUser -Password $Password | Select Name, Version, Build


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

AlbertWT
Virtuoso
Virtuoso
Jump to solution

Hi LucD​,

Thank you for chiming in this thread, I would like to get the VCenter information by looping through multiple VCenter.

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

By using the Connect-VIServer to multiple vCenters and using the pipeline you are looping through all vCenters.
Or does the result miss info from vCenters?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

AlbertWT
Virtuoso
Virtuoso
Jump to solution

Hi LucD​,

yes, you are right, the below command works.

Get-VIServer -Server $VCenter -User $AdminUser -Password $Password | Select Name, Version, Build

However, if I wanted to check for any available VM Snapshot in each of those VCenters, what will be the command?

Get-Snapshot --> does not work after I put it under the above line.

Do I also need to manually disconnect all VI server connection to preserve memory?

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this

You really should stop using Get-VIServer, that cmdlet is very old and not used anymore since Connect-VIServer was introduced.

$VCenter = @('PRDVC01-VM', 'VC03-VA', 'VCenter-PROD01')

$AdminUser = 'DOMAIN\Administrator'

$Password = 'XXyyZZ!@#'


Connect-VIServer -Server $VCenter -User $AdminUser -Password $Password

foreach ($vc in $global:defaultviservers) {

    Get-VM -PipelineVariable vm |

    Get-Snapshot |

    Select-Object @{N = 'vCenter'; E = { $vc.Name } },

        @{N = 'vCenter Version'; E = { $vc.Version } },

        @{N = 'vCenter Build'; E = { $vc.Build } },

        @{N = 'VM'; E = { $_.VM.Name } },

        Name, Description, Created, SizeGB

}

Disconnect-VIServer -Server * -Confirm:$false -Force


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

AlbertWT
Virtuoso
Virtuoso
Jump to solution

That's great, thank you LucD.

I can now reuse the script for executing some command against multiple VCenters.

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos