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.
Try -notcontains
$ds = Get-Datastore | ?{$dsToIgnore -notcontains $_.Name}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try -notcontains
$ds = Get-Datastore | ?{$dsToIgnore -notcontains $_.Name}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
brillaint thanks!