help with the script to get more than one share

Hello,
I have the following script that gets the NTFS permissions for the specified share into the csv file called Sharename.csv

I would like to be able to specify more than one share and then export the results into each share corresponding csv
So for the output for this share \\FileServer01\NYCshare I would like the file to be NYCShare.csv and for another share, for example, CanadaShare into CanadaShare.csv.

Please help. Thank you very much!


# Include only folders from the root path
Get-ChildItem "\\FileServer01\NYCshare" -Recurse | ?{ $_.PsIsContainer } | %{
  $Path = $_.FullName

  (Get-Acl $Path).Access | Select-Object `
    @{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
    InheritanceFlags, PropagationFlags, FileSystemRights, IsInherited
} | Export-CSV "NFCShare.csv"
creative555Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
Something like this.
"NYCshare","CanadaShare" | ForEach `
{
    $share = $_
    # Include only folders from the root path
    Get-ChildItem "\\FileServer01\$share" -Recurse | ?{ $_.PsIsContainer } | %{
        $Path = $_.FullName

        (Get-Acl $Path).Access | Select-Object `
            @{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
            InheritanceFlags, PropagationFlags, FileSystemRights, IsInherited
    } | Export-CSV "$share.csv"
}

Open in new window


You might have to make modifications depending on the source of the share names, and/or the server on which they live.
creative555Author Commented:
Could you please explain what does it do? Also do I need to add anything to this - "NYCshare","CanadaShare"?

Sorry, I am not good with powershell. DO I just change the name from "NYCshare","CanadaShare" to "\\servername\NYCshare" and nothing else and it should work?
footechCommented:
It just loops through the names you provide.  You can add as many names as you like.  You could also have the names in a file and then read it to submit the names to the foreach loop.
Get-Content shares.txt | | ForEach `

Open in new window


The server name is specified on line 5.  It is combined with the share name to form the UNC path.
Defend Against the Q2 Top Security Threats

Were you aware that overall malware worldwide was down a surprising 42% from Q1'18? Every quarter, the WatchGuard Threat Lab releases an Internet Security Report that analyzes the top threat trends impacting companies worldwide. Learn more by viewing our on-demand webinar today!

creative555Author Commented:
Can i specify shares as Unc path? Would that work? The servers are different for each share so I have to specify share like this
\\fileseever01\share1.
creative555Author Commented:
hi,
I specified unc path in the shares txt and it is not working
It throws error: export-csv the network name cannot be found. I checked the path to share and it is correct

Thank you
footechCommented:
"\\FileServer01\NYCshare","\\FileServer02\CanadaShare" | ForEach `
{
    $share = ($_ -split "\\")[-1]
    # Include only folders from the root path
    Get-ChildItem $_ -Recurse | ?{ $_.PsIsContainer } | %{
        $Path = $_.FullName

        (Get-Acl $Path).Access | Select-Object `
            @{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
            InheritanceFlags, PropagationFlags, FileSystemRights, IsInherited
    } | Export-CSV "$share.csv"
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
creative555Author Commented:
Excellent!! This works perfect!! I am posting another question to do the same but with folder owners script. IF you could please help me with the other one. Thank you so much!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.