Home > VMWare > Powershell VMWare Inventory

Powershell VMWare Inventory




###########################################################################
#
# NAME: VM Inventory
#
# AUTHOR: Joshua Schofield
#
# COMMENT: Script to use when wanting Datastore,Host,Name,PowerState,OS,IP, and vCenter server information for all VMs. 
#
#		   
# VERSION HISTORY: 6
#
# VERSION DATE:    08/10/2012
#			
#			
# PreReqs:   Must have vSphere Client and PowerCLI installed		
#					
#					
#					
#
###########################################################################

# Adding all snapins to current PS Session

Get-PSSnapin -Registered | Add-PSSnapin

# Set Variables for Outfile and vCenter Server(s)
$outfile = Read-Host -Prompt "Type the entire path and file name (c:\temp\test.csv) for output file:"
$vc = Read-Host -Prompt 'Enter vCenter Server FQDN or IP Address (If multiple type @("hostname","hostname2"):'

# Popup Window asking to input credentials
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”) | Out-Null
[Windows.Forms.MessageBox]::Show("Please Supply Your vCenter Server Credentials in the next Window”,0, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
$vccred = (Get-Credential)

# Connect to vCenter Server
Connect-VIServer -Server $vc -Credential $vccred

Write-Output "Datastore,Host,VMName,FQDN,Power,OS,IP,vCenter Server" | Out-File $outfile -Force # -Force will overwrite any existing file

Get-Datastore -Server $vc | Sort-Object {$_.name} | % {

$datastore = $_.name

Get-VM -Datastore $datastore | select name,powerstate | % {

$name = $_.name
$power = $_.powerstate
$vmhost = $_.vmhost

Get-VMGuest $name | select hostname,osfullname,ipaddress | % {

$hostname = $_.hostname
$os = $_.osfullname
$ip = $_.IPaddress

Write-Output "$datastore,$vmhost,$name,$hostname,$power,$os,$ip,$vc" | Out-File $outfile -Append

}}} 



Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: