TechColumnist

Directives from a Director (MSP)

Powershell: List all VMs with Datastore

Script to list all the VMs that exist within your vCenter Server with their datastore.

Param(
  [string]$vcServer
)
cls
if (!$vcServer) {Write-Host "No vCenter Server Specified"; exit}
Add-PSSnapin VMware.VimAutomation.Core
$host.ui.rawui.WindowTitle="PowerShell [PowerCLI Module Loaded]"

Connect-VIServer $vcServer

$aDatastoreVM = Get-Datacenter | Get-Datastore | Foreach-Object {
$ds = $_.Name
$_ | Get-VM | Select-Object Name,@{n='DataStore';e={$ds}},VMHost, PowerState, Version, Folder
}

$aDatastoreVM | Export-Csv "D:\scripts\datastore-output.csv" -NoTypeInformation -UseCulture
Disconnect-VIServer $vcServer
Powershell: List all VMs with Datastore was last modified: March 4th, 2014 by TomLasswell

,

Leave a Reply

%d bloggers like this: