Last active
August 29, 2015 14:06
-
-
Save fr0gger03/b9136768a85a7d1b4321 to your computer and use it in GitHub Desktop.
PowerCLI: script to map Virtual Machine to underlying VMFS Datastore (block only)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# you must connect and authenticate to a vCenter server | |
# use Connect-VIServer to do so | |
# establish Export file name | |
$csvname = Read-Host 'Please provide the file path and name for your CSV export' | |
# Gather information on all datacenters and datastores, then enter loop | |
Get-Datacenter | Get-Datastore | Foreach-Object{ | |
# capture datastore name in variable | |
$ds = $_.Name | |
# capture state of datastore in variable | |
$accessible=$_.State | |
# for each datacenter, get the virutal machine, select specific properties, | |
# and export it all to a CSV file | |
$_ | Get-VM | Select-Object @{n=‘VMName’;e={$_.Name}},@{n=’PowerState';e={$_.PowerState}},@{n=‘ESXi Host Name’;e={$_.VMhost}},@{n=‘DataStore’;e={$ds}},@{n=‘Accessible’;e={$accessible}},@{n=’Type’;e={$_.Type}} | Export-CSV $csvname -NoTypeInformation –Append | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment