I am stuck, What I would like to do is exclude datastores within a list of datastore folders when getting a list of datastores.
if I do a get-folder, I get the following (which is expected):
Name Type
---- ----
datastore Datastore
New_Folder Datastore
Internal_Datastores Datastore
I'd like to list out just the datastores in the datastore folder and not the New_Folder and Internal_Datastores folders.
The following works:
$datastore_folder_exclude = @("datastore") #list out the datastore folders to exclude from the report
$ds_fold_exclude = $datastore_folder_exclude.ForEach({ [RegEx]::Escape($_) }) -join '|' #creates a regular expression based on $datastore_folder_exclude variable
$folder = get-folder -type Datastore| where-object {$_.name -notlike $ds_fold_exclude}
foreach ($fold in $folder){get-datastore -location $fold.name}
This lists out the datastores that are in the New_Folder and Internal_Datastores folders.
What I want to do is the opposite though, excluding these two folders.
What I came up with is:
$datastore_folder_exclude = @("New_Folder","Internal_Datastores") #list out the datastore folders to exclude from the report
$ds_fold_exclude = $datastore_folder_exclude.ForEach({ [RegEx]::Escape($_) }) -join '|' #creates a regular expression based on $datastore_folder_exclude variable
$folder = get-folder -type Datastore| where-object {$_.name -notlike $ds_fold_exclude}
foreach ($fold in $folder){get-datastore -location $fold.name}
This does not work, it returns all datastores. actually duplicating the datastores that are IN the folders that I'm attempting to exclude.