VMware Cloud Community
houghtp
Contributor
Contributor
Jump to solution

List of Datastores with exclusions

Hi ,

I'm trying to get a list of datastores for free spaae reporting but I want to exclude certain ones that are contained in a text file (reason being anyone can edit text file and add new datastores to exclude without knowing PowerShell. Then text file is just a list of datastores i want to exclude, 1 per line.

I can't seem to get the comparison operator correct. Script is:

$dsToIgnore = Get-Content c:\Scripts\Powershell\VMware\DataStoreToExclude.txt

$ds = Get-Datastore | ?{$_ -notmatch $dsToIgnore}

I've tried -notmatch, -notlike and also converting my $dsToIgnore variable to a string. I know this is quite simple.

any help or better suggestions on how to acomplish this appreciated.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try -notcontains

$ds = Get-Datastore | ?{$dsToIgnore -notcontains $_.Name}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try -notcontains

$ds = Get-Datastore | ?{$dsToIgnore -notcontains $_.Name}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
houghtp
Contributor
Contributor
Jump to solution

brillaint thanks!

0 Kudos