-
-
Save Juanito99/44bcc30cd96128b0bcf3fc31c6436474 to your computer and use it in GitHub Desktop.
I was able to figure it out and added it to an onboarding script I use when scoping new AD based environments. This is very helpful and a great time saver. Thank you very much for this, and as to not be the guy that says "I figured it out" without leaving the solution, please see my added tidbits to allow for a call to AD to pull all active servers, export to list, and then run your code against all servers in the list, resulting in a subsequent CSV dump of all known shares, share permissions, and NTFS permissions across the AD Domain servers. Again, thank you very much for this.
Get Server Shares Permissions
..
Thank you @MrMcGuinty Very appreciated :-)
Sorry @rich-houk , I am presently not able to adjust the script. Hope I can find some time in the future.
Hello @Juanito99 ,
Great script! Exactly what I needed to enumerate shares and get the share permissions.
I wanted to correct the regular expression matching being done in the IF statement. You have:
if (($share.Name -notmatch '(?im)^[a-z]{1,1}\$') -and ($share.Name -notmatch '(?im)^[admin]{5,5}\$') -and ($share.Name -notmatch '(?im)^[ipc]{3,3}\$') -and ($share.Name -notmatch '(?im)^[print]{5,5}\$'))
Breaking them down, the first is:
(?im)^[a-z]{1,1}\$
The quantifier
{1,1}
can be simplified to{1}
(?im)^[a-z]{1}\$
The last 3 are trying to match admin, ipc, and print.
(?im)^[admin]{5,5}\$
(?im)^[ipc]{3,3}\$
(?im)^[print]{5,5}\$
Using brackets will search for each character individually, not as a word. For example, if we just look at the search for admin:
(?im)^[admin]{5,5}\$
This search is looking for any 5-character combination of the letters a, d, m, i, and n. Along with admin, the following will also match:
aaaaa$
dainm$
MINAD$
MMNNA$
To perform a literal search of the characters/word, use the following:
(?im)^admin\$
(?im)^ipc\$
(?im)^print\$
To shorten the whole thing, you can combine all of these into one query by creating a group:
if ($share.Name -notmatch '(?im)^([a-z]{1}|admin|ipc|print)\$$')
Also added a second $ at the end to match end of string/line.
@DHCook Great feedback! - Thank you :-)
How would I modify this to not exclude ANY permission holders, such as Administrators? My attempts at cutting those sections are resulting in the script producing no output.
Hello @Juanito99 ,
Great script! Exactly what I needed to enumerate shares and get the share permissions.
I wanted to correct the regular expression matching being done in the IF statement. You have:
if (($share.Name -notmatch '(?im)^[a-z]{1,1}\$') -and ($share.Name -notmatch '(?im)^[admin]{5,5}\$') -and ($share.Name -notmatch '(?im)^[ipc]{3,3}\$') -and ($share.Name -notmatch '(?im)^[print]{5,5}\$'))
Breaking them down, the first is:
(?im)^[a-z]{1,1}\$
The quantifier
{1,1}
can be simplified to{1}
(?im)^[a-z]{1}\$
The last 3 are trying to match admin, ipc, and print.
(?im)^[admin]{5,5}\$
(?im)^[ipc]{3,3}\$
(?im)^[print]{5,5}\$
Using brackets will search for each character individually, not as a word. For example, if we just look at the search for admin:
(?im)^[admin]{5,5}\$
This search is looking for any 5-character combination of the letters a, d, m, i, and n. Along with admin, the following will also match:
aaaaa$
dainm$
MINAD$
MMNNA$
To perform a literal search of the characters/word, use the following:
(?im)^admin\$
(?im)^ipc\$
(?im)^print\$
To shorten the whole thing, you can combine all of these into one query by creating a group:
if ($share.Name -notmatch '(?im)^([a-z]{1}|admin|ipc|print)\$$')
Also added a second $ at the end to match end of string/line.