Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sn180py
Created November 26, 2018 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sn180py/669224124a7dd0ebceaaf3f9e1073393 to your computer and use it in GitHub Desktop.
Save sn180py/669224124a7dd0ebceaaf3f9e1073393 to your computer and use it in GitHub Desktop.
Audit Fileshare from Hybrid Worker
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