I am trying filter by the name of each share using $Share.Name
. However, when I try to use -contains
in the if
statement below, I get no results.
The result I want should be ADMIN$ - C:\ADMIN$
I am working my way to being able to have a variable like: $ExcludeShares = "ADMIN$"
and filtering based on if the $String.Name
is in $ExcludeShares
I am open to ideas on other ways to filter this.
Thanks in advance!
function GetAllUsedShares{
[psobject]$Shares = Get-WmiObject -Class win32_share
Foreach($Share in $Shares){
$name = [string]$Share.Name
if ($name -contains 'admin'){
Write-Host $Share.Name - $Share.Path
}
}
}
Aucun commentaire:
Enregistrer un commentaire