Hello Guys and Gals,
I am trying to figure out this script, where when a user specifies a path. The script will go there list all of the child items, show the users, groups, and permissions for those items and then save them to either text file or excel file. So far I kinda of got it working in 2 separate scripts and would love to get some help in combining the two.
Below are the 2 different functions, the Subfolder function outputs exactly what I want, just not in the format I like or need. The MainFolder function outputs it exactly how I want it but it doesn't go to
any subfolders. The best I can come up with is to turn individual network path locations from the SubFolders function, throw those into an array and then pass that to MainFolder function; which will all be in a for-each object loop or something along those
lines. Been stuck on this for a bit and would love any and all help
either in combining these two functions or in coming up with a solution
Function SubFolders($a){<# this function gets the the network location as an input it then gets all the child items for that network location, finds the access control lists filters them according to the network path and username/group and finally outputs it to a file called PermissionsOn.txt on the C drive #> $networkLocation = $a gci $networkLocation|Get-ACL|fl -Property Path,accesstostring |Out-File c:\SubfolderPermissions.txt -Width 120 #Start-Sleep -Seconds 1 }
Function MainFolder($share) {<# this function gets the network location of a particular share lists every member that has access to it filters out the Domain Admins group, Account Type, Share and NetID if there are users that are part of no group it will also display them #> $NotReturnUserGroup = "DOMAIN.local\domain admins" $acls=(get-acl $share).Access $acls | foreach { $rights=$_.filesystemrights.tostring() get-qadobject $_.IdentityReference.value | foreach { if ($_.Type -eq "group") { $AGT = $_.NTAccountName $Type = $_.Type Foreach ($member in (get-qadgroupmember $_ -Indirect | where {$_.type -match "user"})) { #the if statement filters out specific group and/or users that are part of that group if ($_.NTAccountName -notlike $NotReturnUserGroup){ $obj=new-object PSObject $obj | Add-Member -MemberType NoteProperty -Name "Name" -Value $member.Name #$obj | Add-Member -MemberType NoteProperty -Name "NetID" -Value $member.logonname #$obj | Add-Member -MemberType NoteProperty -Name "Share" -Value $share $obj | Add-Member -MemberType NoteProperty -Name "Rights" -Value $rights $obj | Add-Member -MemberType NoteProperty -Name "AccessGivenTo" -Value $_.NTAccountName #$obj | Add-Member -MemberType NoteProperty -Name "AccountType" -Value $_.Type write $obj } } } elseif ($_.Type -eq "user") { $obj=new-object PSObject $obj | Add-Member -MemberType NoteProperty -Name "Name" -Value $_.Name #$obj | Add-Member -MemberType NoteProperty -Name "NetID" -Value $_.logonname #$obj | Add-Member -MemberType NoteProperty -Name "Share" -Value $share $obj | Add-Member -MemberType NoteProperty -Name "Rights" -Value $rights $obj | Add-Member -MemberType NoteProperty -Name "AccessGivenTo" -Value $_.NTAccountName #$obj | Add-Member -MemberType NoteProperty -Name "AccountType" -Value $_.Type write $obj } } } }