Created
November 26, 2018 03:54
-
-
Save sn180py/669224124a7dd0ebceaaf3f9e1073393 to your computer and use it in GitHub Desktop.
Audit Fileshare from Hybrid Worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
[string]$ServerPath, | |
[string]$AuditShare, | |
[string]$OutputFolder | |
) | |
$ResultPath = "c:\sharepointfiles" | |
$Filename = $OutputFolder | |
$TargetShare = "$Serverpath\$AuditShare" | |
#About to Audit the Folder | |
write-output "$targetServer audit starting" | |
$Folders = dir $targetshare | |
ForEach ($Folder In $Folders){ | |
$ACLs = Get-Acl $Folder.FullName | ForEach-Object { $_.Access } | |
} | |
#Output Results from above to (this folder is precreated for this example) | |
$ACLs >> "$ResultPath\$AuditShare-$Filename.txt" | |
#check members of the Global Group | |
$globalgroups = ($ACLs | where {$_.identityreference -like '*GG*'}).Identityreference.Value.Split("\")[1] | |
ForEach ($GlobalGroup in $GlobalGroups) | |
{ | |
$groupmembers = (Get-ADGroupMember -identity $globalgroup).name | |
$groupmembers >> "$ResultPath\$AuditShare-$globalgroup.name-$Filename.txt" | |
} | |
Write-Host "Audit Completed. Results saved to $ResultPath" | |
write-host "sending all files to zip" | |
$FilesTocompress = Get-ChildItem C:\sharepointfiles\*$Filename*.* | |
Compress-Archive $FilesTocompress -DestinationPath "c:\sharepointfiles\$AuditShare-$Filename.zip" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment