Mon. Jan 3rd, 2022
Function Get-SiteCollectionPermissionsAudit([String]$WebDomain,[String]$Sprint,[String]$SiteURL,[String]$SiteTitle,[String]$ReportOutput, $Credentials)
{
    Try{

    Write-Host "Checking for file - " $FilePath -ForegroundColor Yellow
    $Timestamp = GetTimeStamp
    $ReportOutputFilePath = $ReportOutput + '\' + $SiteTitle +'_CollectionPermissionsAudit ' + $Timestamp + '.xlsx'
    if (Test-Path $ReportOutputFilePath) 
    {
         Write-Host "Permissions Report already exists - " $FilePath -ForegroundColor Yellow
    }else{

    $global:sitePermissionsSheetRow = 2
    $global:listPermissionsSheetRow = 2
    $global:itemPermissionsSheetRow = 2
    $global:GroupMembersSheetRow = 2

    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $ctx.Credentials = $credentials;
    $rootWeb = $ctx.Web
    $ctx.Load($rootWeb)
    $ctx.ExecuteQuery()
    $SiteTitle = $rootWeb.Title

    #Create Output Workbook
    $excel = New-Object -comobject Excel.Application
    $workbook = $excel.Workbooks.Add()
    $sitePermissionsSheet = $workbook.Worksheets.Item(1);
    $listPermissionsSheet = $workbook.Worksheets.Add()
    $itemPermissionsSheet = $workbook.Worksheets.Add()
    $groupMembersSheet = $workbook.Worksheets.Add()

    ContructWorksheets -sitePermissionsSheet $sitePermissionsSheet -listPermissionsSheet $listPermissionsSheet -itemPermissionsSheet $itemPermissionsSheet -groupMembersSheet $groupMembersSheet
    GetPermissionsForWeb -web $ctx.Web -ctx $ctx -sitePermissionsSheet $sitePermissionsSheet -listPermissionsSheet $listPermissionsSheet -itemPermissionsSheet $itemPermissionsSheet
    GetGroupMembers -web $ctx.Web -ctx $ctx -memberSheet $groupMembersSheet -credentials $psCreds

    
        $excel.Visible = $true
        Add-Type -AssemblyName Microsoft.Office.Interop.Excel
        $xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlWorkbookDefault
        
        #Delete the Output Report, if exists
        write-host 'Saving to' $ReportOutputFilePath -ForegroundColor Green

        $excel.ActiveWorkbook.SaveAs($ReportOutputFilePath, $xlFixedFormat)
        $excel.Workbooks.Close();
        $excel.Quit()
        UploadFileToList -ListName $Sprint -FolderName $SiteTitle -FilePath $ReportOutputFilePath
    }#if
    }
    Catch {
        write-host -f Red "Error Generating permissions audit Report!" $_.Exception.Message
    }
}

This website uses cookies. By continuing to use this site, you accept our use of cookies.