Automation

 View Only
  • 1.  Script to get multiple VCenter information?

    Posted Apr 22, 2020 02:31 PM

    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.



  • 2.  RE: Script to get multiple VCenter information?

    Posted Apr 22, 2020 02:40 PM

    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



  • 3.  RE: Script to get multiple VCenter information?

    Posted Apr 22, 2020 11:38 PM

    Hi LucD​,

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



  • 4.  RE: Script to get multiple VCenter information?

    Posted Apr 23, 2020 06:24 AM

    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?



  • 5.  RE: Script to get multiple VCenter information?

    Posted Apr 23, 2020 07:15 AM

    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?



  • 6.  RE: Script to get multiple VCenter information?
    Best Answer

    Posted Apr 23, 2020 07:38 AM

    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



  • 7.  RE: Script to get multiple VCenter information?

    Posted Apr 23, 2020 08:24 AM

    That's great, thank you LucD.

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