# encoding: ascii
# api: powershell
# title: mGet-DatastoreList
# description: A version of the VMware Get-Datastore cmdlet that filters out datastore we don’t want to use for VMs by type of datastore and our naming conventions for the datastore naming indicating what kind of data is on the datastore.  Line 9 will have to be updated for your own environment.
# version: 0.1
# type: function
# author: monahancj
# license: CC0
# function: mGet-DatastoreList
# x-poshcode-id: 2448
# x-archived: 2014-02-09T10:28:02
# x-published: 2011-01-07T12:24:00
#
#
Function mGet-DatastoreList {
#Parameter- Name of the VMware cluster to choose a datastore from.
param($Cluster)

#get alphabetically last ESX host in the VMware cluster (it's likely the last host added to the cluster, so this might smoke out any problems)
$VMH = get-vmhost -Location $cluster | Where-Object { ($_.ConnectionState -eq "Connected") -and ($_.PowerState -eq "PoweredOn") } | Select-Object -Property Name | Sort-Object Name | Select -Last 1 -Property Name

# Get all the datastores, filtered for exclusions
$DSTs = Get-Datastore -VMHost $VMH.Name | Where-Object { ($_.Type -eq "VMFS") -and ($_.Name -notmatch "local") -and ($_.Name -notmatch "iso") -and ($_.Name -notmatch "template") -and ($_.Name -notmatch "CLD") -and ($_.Name -notmatch "TRX") }

Write-Output $DSTs
}
