Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Made a script to find share paths; How do I exclude with certain criteria

$
0
0

I have a few file server clusters with a bunch of shares on them and I need to add permissions for a security group to all the shares. The first step is getting all the shares. I can do this with gwmi -class win32_share so I wrote a powershell script to do this across all the file servers. It works as expected with one issue, it gives me the share paths plus the path to the drive letters (i.e. \\FileServer\J$). I am thinking I can put some kind of IF statement to exclude anything with *$* but I don't know how to go about this. Any thoughts?

Import-Module activedirectory
$ErrorActionPreference = "SilentlyContinue"
$ComputerName=Get-ADComputer -Filter {name -like "FS*"} | %{$_.dnshostName}
$Computers=gwmi -class win32_share -computername $ComputerName
        ForEach ($Computer in $Computers){
        Write-Host $Computer.Name            
                                                                 }


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>