Reply to Message

View discussion in a popup

Replying to:
BBB36
Enthusiast
Enthusiast

Find list of datastores of a certain free space in clusters in multiple vCenters

I'm looking to get a list of datastores of at least 8TB free space in any cluster found in each vCenters then export the vCenter, Datacenter, cluster name and datastores information to a CSV file. The script I currently gathers some results but isn't accurate. For exapmple I don't think I have the calculated properties right because the current exported results displays a lot of information I don't need. Can someone please help refine it so it displays the results exacly how I need it to?

I still haven't also figured out how to include the vCenter name in the script, which I've pasted below. Thank you.

$Creds = Get-Credential -Message "Enter username and password" -ErrorAction SilentlyContinue;

$vCenters = (Get-Content "C:\VC.txt")

foreach ($vCenter in $vCenters) {

$Connection = Connect-VIServer $vCenter -Protocol https -Credential $Creds

        if (!$Connection){return "ERROR: No connection to $vCenter"}

}

Get-Cluster -Server $global:DefaultVIServers -PipelineVariable cluster |

    ForEach-Object -Process {

    Get-Datastore -Name *

        Select   @{N='Cluster';E={$_Cluster.Name}}

        @{N='Datacenter';E={$_.Datacenter}}

        @{N='Datastore Browser Path';E={$_.DatastoreBrowserPath}}

        @{N='Datastore Name';E={$_.Name}}

        @{N='Datastore Capacity';E={$_.CapacityGB}}

        @{N='Datastore Free Space';E={$_.FreeSpaceGB}} |

        Where ({$_.FreeSpaceGB -like "817*" -and $_.DatastoreBrowserPath -notcontains "*local-storage-1"}) | Select -First 1

}|

Export-Csv -Path .\Output.csv -Append -NoTypeInformation -UseCulture

Tags (1)
Reply
0 Kudos