Hi All,
Good Morning!
I am trying to write a script to get all datastore in the cluster and it should give me the data in table format like datastorename, clustername,capacityGB, freespaceGB,usedspace=freespaceGB/capacityGB *100
#$VCName = Read-Host "Enter the VC name "
Connect-VIServer VCname -WarningAction Continue
clear
$cls = get-cluster
Get-Datastore|where {$_.name -notlike "*local*" -and $_.name -notlike "*template*"}| Format-Table name ,capacityGB, freespaceGB -AutoSize
the above get-datastore cmd is giving me the list of all the datastore and capacityGB, freespaceGB but not the cluster name. I tried for loop as well but not getting the desired result.
Can someone correct my script above.
Try like this
$VCName = Read-Host "Enter the VC name "
Connect-VIServer VCname -WarningAction Continue
clear
Get-Cluster -PipelineVariable cluster |
Get-Datastore |
where {$_.name -notlike "*local*" -and $_.name -notlike "*template*"} |
Select @{N='Cluster';E={$cluster.Name}},Name,CapacityGB,FreespaceGB,@{N='UsedSpace';E={$_.FreeSpaceGB/$_.CapacityGB*100}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this
$VCName = Read-Host "Enter the VC name "
Connect-VIServer VCname -WarningAction Continue
clear
Get-Cluster -PipelineVariable cluster |
Get-Datastore |
where {$_.name -notlike "*local*" -and $_.name -notlike "*template*"} |
Select @{N='Cluster';E={$cluster.Name}},Name,CapacityGB,FreespaceGB,@{N='UsedSpace';E={$_.FreeSpaceGB/$_.CapacityGB*100}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks For reply LucD that gives the below desired data. Can i get this data in table format.
Cluster : ClusterName
Name : DataStoreName
CapacityGB : 8191.75
FreeSpaceGB : 5198.4091796875
UsedSpace : 63.459079924161503952146977140
Can i get this data in table format. if i pipe it again with format-table as below
Get-Cluster -PipelineVariable cluster |
Get-Datastore |
where {$_.name -notlike "*local*" -and $_.name -notlike "*template*"} |
Select @{N='Cluster';E={$cluster.Name}},Name,CapacityGB,FreespaceGB,@{N='UsedSpace';E={$_.FreeSpaceGB/$_.CapacityGB*100}} | Format-Table datastoreName, clusterName, CapacityGB,FreespaceGB,UsedSpace -Autosize
Name clusterName CapacityGB FreespaceGB UsedSpace
DataStoreName ClusterName 8191.75 5198.40 63.45
Sure, like this
$VCName = Read-Host "Enter the VC name "
Connect-VIServer VCname -WarningAction Continue
clear
Get-Cluster -PipelineVariable cluster |
Get-Datastore |
where {$_.name -notlike "*local*" -and $_.name -notlike "*template*"} |
Select @{N='Cluster';E={$cluster.Name}},Name,CapacityGB,FreespaceGB,@{N='UsedSpace';E={$_.FreeSpaceGB/$_.CapacityGB*100}} |
Format-List
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
even after |format-list its giving data into rows and i would like to get it per column like below
Name clusterName CapacityGB FreespaceGB UsedSpace
DataStoreName ClusterName 8191.75 5198.40 63.45
Then you use a Format-Table
$VCName = Read-Host "Enter the VC name "
Connect-VIServer VCname -WarningAction Continue
clear
Get-Cluster -PipelineVariable cluster |
Get-Datastore |
where {$_.name -notlike "*local*" -and $_.name -notlike "*template*"} |
Select @{N='Cluster';E={$cluster.Name}},Name,CapacityGB,FreespaceGB,@{N='UsedSpace';E={$_.FreeSpaceGB/$_.CapacityGB*100}} |
Format-Table -AutoSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a ton LucD. that exactly i wanted.
Hi LucD, I see "PipelineVariable" won't be recognized under PowerShell version we use. Is there alternate how we can achieve this under PowerShell v3? I saw your article under below link, however, unable to put it together as usable script!
Its just that we want to export Cluster details (not SDRS) as well when exporting datastore list (Name, capacity, free).
https://communities.vmware.com/thread/595182
Thanks,
Hari.
Sure, try like this
Connect-VIServer VCname -WarningAction Continue
clear
Get-Cluster | ForEach-Object -Process {
$cluster = $_
Get-Datastore -RelatedObject $cluster |
where { $_.name -notlike "*local*" -and $_.name -notlike "*template*" } |
Select @{N = 'Cluster'; E = { $cluster.Name } }, Name, CapacityGB, FreespaceGB, @{N = 'UsedSpace'; E = { $_.FreeSpaceGB / $_.CapacityGB * 100 } }
} | Format-Table -AutoSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
that did the magic! Thank you.
Output seems muffled, is there way to correct it? I remember using Autofit should do it but not sure whats wrong. First and second is cluster and DS name and then all cut short.
Dev-15 Dev-15_001 ...75
Thank you!
That's probably due to the linelength of the console.
Send it a file (for example with Export-Csv), there you should see all values and complete.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
replace format-table with export-csv and it did given desired output!
Thank you very much for the prompt help! 🙂
Thanks,
Hari.