How to gather your vCenter inventory data with this VMware PowerShell script

Stock studies are a standard request when administering a VMware vCenter setting. Find out how this VMware PowerShell script could make such requests fast and straightforward.


Picture: Shutterstock/SidorArt

As somebody who administers a VMware digital setting and has been by way of a number of firm mergers, working stock audits is second nature to me. It is all the time a good suggestion to take care of a present stock of your digital machines as a way to finest handle the setting, however because of the ever-changing nature of expertise, the place techniques are constructed or decommissioned at a daily tempo, it may be like attempting to hit a transferring goal.

As traditional, scripting is the important thing right here. This VMware-based PowerShell script may help make amassing your stock knowledge fast and straightforward. My colleague Brad Doran, senior technical account supervisor at Amazon Internet Providers, supplied me this script and I’m utilizing it right here together with his permission. You’ll be able to copy and paste it to a neighborhood file known as VMware_Inventory.ps1, for example.


Use Home windows 10 (it is theoretically potential to run this in Home windows 7, however it’s possible you’ll expertise complications with outdated PowerShell variations since this script requires PowerShell 4.0 at minimal).

Run Home windows PowerShell ISE as Administrator (you too can use common PowerShell, however I discover ISE finest for optimum outcomes in addition to error analysis).

Set up the VMware PowerCLI module utilizing this remark throughout the PowerShell ISE Window:

Set up-Module -Title VMware.PowerCLI

In the event you get an error that you just want NuGet supplier model 2.8.201 simply click on Sure and the method will obtain and set up it for you. It’ll take a couple of moments and you may then must click on Sure to proceed, and in a couple of extra moments you will note this system putting in the associated VMWare.PowerCLI packages.

SEE: Microsoft PowerShell: Discover ways to automate your workday (TechRepublic Academy)

Because the script requires the VMware.VimAutomation.Core module additionally be sure it is the most recent model (as of October 2021) put in through this command:

Set up-Module -Title VMware.VimAutomation.Core -RequiredVersion

Click on Sure to proceed and in a couple of extra moments you will note this system putting in the associated VMWare bundle.

In the event you obtain an error stating: “PackageManagementInstall-Package deal : Authenticode issuer ‘CN=VeriSign Class 3 Public Major Certification Authority – G5, OU=”(c) 2006 VeriSign, Inc. – For licensed use solely”, OU=VeriSign Belief Community, O=”VeriSign, Inc.”, C=US’ of the brand new module ‘VMware.VimAutomation.Core’ with model ‘’ is just not matching with the authenticode issuer ‘CN=DigiCert Trusted Root G4,, O=DigiCert Inc, C=US’ of the previously-installed module ‘VMware.VimAutomation.Core’ with model ‘’. In the event you nonetheless need to set up or replace, use-SkipPublisherCheck parameter”

run this command:

Set up-Module -Title VMware.VimAutomation.Core -RequiredVersion -SkipPublisherCheck

You too can go right here and obtain the most recent model to (“C:Program Recordsdata (x86)VMWareInfrastructurePowerCLIModules”):

Customizing the script

The script depends on these variables (Determine A):

$vcs = @(“vCenterFQDN”) # FQDN of your vCenter server.
$logFile = “C:TempVMInventory.csv” # The place you need to save the CSV file
$vcsCluster = “*” # Filters which cluster you need to pull VM stats from
$businessUnitName = “Ingredient” # Title of enterprise unit that the script is gathering stats for


Determine A

For $vcs, you may substitute @(“vCenterFQDN”) with the title of your vCenter server in quotes; in any other case the script will immediate you to enter the title.

For $logFile, the logfile path and title might be modified accordingly.

For $vcsCluster you may specify the cluster to collect knowledge from, or go away this line as is to drag info from all clusters.

For $businessUnitName, substitute the instance “Ingredient” entry with your corporation unit, division or group.

SEE: Guidelines: Server stock (TechRepublic Premium)

Working the script

Click on File then Open and browse to the place you saved the script file to pick it then load it into PowerShell ISE. Hit the inexperienced button to execute it. 

In the event you get an error associated to safety insurance policies or the script being unsigned, run this command to permit native scripts and distant signed scripts:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned 

In the event you left the $vcs variable as is you can be prompted to enter the vCenter server title (Determine B).


Determine B

When you enter the title you will be prompted to authenticate to vCenterj (Determine C). Be certain to make use of an account with administrator-level credentials.


Determine C

You’ll then see the script working and actively gathering knowledge (Determine D).


Determine D

The script will show the outcomes, in addition to save the main points to “C:TempVMInventory.csv” for those who left the associated variable as is (Determine E).


Determine E

(Observe I’ve eliminated the FQDN entries that had been listed since this was run in opposition to an lively enterprise setting.)  

Thanks, Brad, for a superb device each VMware administrator ought to have of their toolkit!

Please contact me through the e-mail hyperlink beneath (to the left of “Full Bio | See all of Scott’s content material”) you probably have any questions or points working this script.

#Requires -Model 4
#Requires -Modules VMware.VimAutomation.Core
    Create a list in CSV format of digital machines in vCenter.
    This script is supposed to carry out a list of Digital Machines. It could actually connect with a number of vCenters to drag
    statistics from and it might probably pull statistics from a number of Host Clusters. This script performs read-only operations.
    Output is formatted as CSV utilizing a regular format.
    Variable Particulars
    $vcs - An array containing the record of vCenter servers to connect with.
    $logFile - The situation of the place to avoid wasting the output in CSV format.
    $vcsCluster - The title of the cluster. It accepts wildcard characters, nevertheless it can't be empty.
    $businessUnitName - the busines unit, group or division which owns/helps this setting
    Credential Necessities
    $vcsCreds - A person credential that has entry to login to vCenter with Learn-Solely rights at a minimal.
    $wmiCreds - A person credential that has entry to carry out WMI queries domestically on the Home windows Digital Machines
# Edit these variables to your particular setting
$vcs = @("vCenterFQDN")                 # FQDN of your vCenter server.
$logFile = "C:TempVMInventory.csv"    # The place you need to save the CSV file
$vcsCluster = "*"                       # Filters which cluster you need to pull VM stats from.
$businessUnitName = "Ingredient"     # Title of Enterprise Unit that the script is gathering stats for
if($vcs -contains "vCenterFQDN"){
    $vcs = Learn-Host -Immediate "FQDN of vCenter Server"
$vcsCreds = Get-Credential -Message "vCenter Credentials"
#$wmiCreds = Get-Credential -Message "WMI Credentials"
Import-Module VMware.VimAutomation.Core
Join-VIServer $vcs -Credential $vcsCreds | Out-Null
$vms = Get-Cluster -Title $vcsCluster | Get-VM
$depend = 0
$outcomes = @()
$Script:ProgressPreferenceOriginal = $ProgressPreference
foreach($vm in $vms) Choose-Object -Skip 1) -join '.')
    Add-Member -InputObject $object -MemberType NoteProperty -Title Location -Worth " "
    Add-Member -InputObject $object -MemberType NoteProperty -Title IPAddress -Worth ($vm.Visitor.IPAddress -join ", ")
    Add-Member -InputObject $object -MemberType NoteProperty -Title Perform -Worth " "
    Add-Member -InputObject $object -MemberType NoteProperty -Title PorV -Worth "Digital"
    Add-Member -InputObject $object -MemberType NoteProperty -Title vCluster -Worth ($vm 
# The Type-Object is particularly arrange in order that the Export-Csv and Out-GridView don't truncate the properties of the person PSObjects in
# the array.
$outcomes | Out-GridView
$outcomes | Export-Csv -Path $logFile -NoTypeInformation
Write-Host "Output saved to $logFile"
Disconnect-VIServer -Server * -Verify:$false -Drive | Out-Null

Additionally see

  • Home windows 11 cheat sheet: All the things it is advisable know (free PDF) (TechRepublic)
  • Extra must-read Microsoft protection (TechRepublic on Flipboard)
  • Handle Energetic Listing with these 11 PowerShell scripts (TechRepublic Premium)
  • Prime 5 programming languages for techniques admins to be taught (free PDF) (TechRepublic)
  • Recent Articles


    Related Stories

    Leave A Reply

    Please enter your comment!
    Please enter your name here

    Stay on op - Ge the daily news in your inbox