I'd like to be able to list the datastore details for 12 vcenters (vcenter name, datastore name, free space in GB, used in GB, total GB) but I'm new to powershell. I've found plenty of scripts that lists similar information but without the Vcenter. Does anyone know where I can find a script for this?
Something like this
foreach($vc in $defaultVIServers){ Get-Datastore -Server $vc |
Select @{N="vCenter";E={$vc.Name}},
Name,
CapacityMB,
FreeSpaceMB,
@{N="UsedSpaceMB";E={$_.CapacityMB - $_.FreeSpaceMB}} }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Something like this
foreach($vc in $defaultVIServers){ Get-Datastore -Server $vc |
Select @{N="vCenter";E={$vc.Name}},
Name,
CapacityMB,
FreeSpaceMB,
@{N="UsedSpaceMB";E={$_.CapacityMB - $_.FreeSpaceMB}} }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Seems I missed some of your requirements in the title of the post.
Try this
$report = @() foreach($vc in $defaultVIServers){ foreach($cluster in (Get-Cluster -Server $vc)){ Get-Datastore -VMHost (Get-VMHost -Location $cluster) | %{ $row = "" | Select vCenter,Cluster,Datastore,CapacityMB,FreeSpaceMB,UsedSpaceMB $row.vCenter=$vc.Name $row.Cluster=$cluster.Name $row.Datastore= $_.Name $row.CapacityMB=$_.CapacityMB $row.FreeSpaceMB=$_.FreeSpaceMB $row.UsedSpaceMB=$_.CapacityMB - $_.FreeSpaceMB $report += $row
} } } $report | Export-Csv "C:\ds-report.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hmmm I get some errors when I try to use that snippet:
Get-Datastore : Cannot bind parameter 'VMHost'. Cannot convert the "" value of type "System.Management.Automation.PSCus
tomObject" to type "VMware.VimAutomation.ViCore.Types.V1.Inventory.VMHost".
At C:\scripts\datastores\test.ps1:20 char:30
+ Get-Datastore -VMHost <<<< (Get-VMHost -Location $cluster) | %{
+ CategoryInfo : InvalidArgument: (:) [Get-Datastore], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore
WHich PowerCLI version are you using ?
Get-PowerCLIVersion
I tested the script in PowerCLI 5.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PowerCLI Version
----------------
VMware vSphere PowerCLI 4.1 U1 build 332441
---------------
Snapin Versions
---------------
VMWare vSphere PowerCLI 4.1 U1 build 332441
I updated to version 5 but I get the same errors.. on the highlighted row
Add-PSsnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
$defaultVIServers = @("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11")
Connect-VIServer $defaultVIServers
$report = @()
foreach($vc in $defaultVIServers){
foreach($cluster in (Get-Cluster -Server $vc)){
Get-Datastore -VMHost (Get-VMHost -Location $cluster) | %{
$row = "" | Select vCenter,Cluster,Datastore,CapacityMB,FreeSpaceMB,UsedSpaceMB
$row.vCenter=$vc.Name
$row.Cluster=$cluster.Name
$row.Datastore= $_.Name
$row.CapacityMB=$_.CapacityMB
$row.FreeSpaceMB=$_.FreeSpaceMB
$row.UsedSpaceMB=$_.CapacityMB - $_.FreeSpaceMB
$report += $row }
}
}
$report | Export-Csv ".\report.csv" -NoTypeInformation -UseCulture
Disconnect-VIServer * -confirm:$false -force:$true
The variable $defaultVIServers is a pre-defined variable.
It holds all the connections (Connect-VIServer) you have opened.
Perhaps try using another variablename for that.
$myVC = @("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11")
Connect-VIServer $myVC
...
And you are working in mult-mode I assume ?
Do a
Get-PowerCLIConfiguration
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I see. Let me adjust the variable on the array.
Proxy Policy Default Server
Mode
------------ ---------------
UseSystemProxy Multiple
That did it! Thanks! Do you think it would be possible to add what the datastore resides on IE. find out if it is on a Netapp vs. a VMMax.. etc? I might add another post to discuss that as a seperate issue.
That should be possible.
From the datastore extent one can find the corresponding Lun and from there the model.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference