Date and Month display

Users Full Control report from Multiple Site Collection

<#
******------------------------------------------------------------------------------------------------------------------------------******
Author          -> Shiv Mangal Singh
Date            -> 17th Feb - 2017
Description     -> This Script will generate a Full Control report for Multiple Site Collection with Site URL, Title, Site collection Size,
                   Content database Name, Permission Type, Permission and Login Name details.

Site Collection Name --> $filepath ="D:\contosoMW_Team\Shiv\PS\SiteColl.txt" | Read All Site Collections name from SiteColl.txt file

# Report generated  directory name / Report location
$FileUrl =$currentdir +"\"+ "Report_" +$currentdatetime+ ".CSV"

******------------------------------------------------------------------------------------------------------------------------------******
 #>
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue


# To get the current directory where the PowerShell Script is residing
$currentdir = Convert-Path(Get-Location -PSProvider filesystem)
# To get the current data & time for report
$currentdatetime =Get-Date -Format "yyyy-MM-d.HH-MM-ss"
# Generated report directory name
$FileUrl =$currentdir +"\"+ "Report_" +$currentdatetime+ ".CSV"

# Read All Site Collections name from SiteColl.txt file
$filepath ="D:\contosoMW_Team\Shiv\PS\SiteColl.txt"
$SiteColl = Get-Content $filepath
 
    # Write CSV- TAB Separated File) Header

    "URL `t Title `t Site Size's in MB `t Content Database `t PermissionType `t Permissions  `t LoginName" | out-file $FileUrl
 
    #Loop throuh all Site collection level
     foreach($sitename in $SiteColl)
     {
      $site = Get-SPWeb $sitename
      $sitesize = Get-SPSite $sitename
     
      # Get the Site Collection Size in MB.
         $sizeinKB =$sitesize.Usage.Storage
         $sizeinMB=$sizeinKB/1024/1024
         $sizeinMB = [Math]::Round($sizeinMB,2)
         Write-host $sizeinMB

      if($site -ne $null)
      {
            #Iterate through all SPRoleAssignments on the web
             foreach($WebRoleAssignment in $site.RoleAssignments )
              {
              #Is it a User Account?
              if($WebRoleAssignment.Member.userlogin)  
               {  
                    $WebUserPermissions=@()
                     foreach ($RoleDefinition  in $WebRoleAssignment.RoleDefinitionBindings)
                      {
                            $FullPerm ="Full Control"
                            if($RoleDefinition.Name.Contains($FullPerm))
                            {
                             $WebUserPermissions += $RoleDefinition.Name +";"
                             #Send the Data to report generated directory
                             "$($site.Url) `t $($site.Title) `t $sizeinMB `t $($sitesize.ContentDatabase.Name) `t Direct Permission `t $($WebUserPermissions)  `t $($WebRoleAssignment.Member.LoginName)" | Out-File $FileUrl -Append
                             }
                       }
                }
                #Its a SharePoint Group, So search inside the group and check if the user is member of that group
                else
                 {
                       foreach($user in $WebRoleAssignment.member.users)
                       {
                            #Get the Group's Permissions on site
                             $WebGroupPermissions=@()
                              foreach ($RoleDefinition  in $WebRoleAssignment.RoleDefinitionBindings)
                                {
                                # $grpControlFullPerm ="Full": Wehave taken this variable to get the Full control permission or wherever the custom permissions name alias Full
                                   $grpControlFullPerm ="Full"
                                    if($RoleDefinition.Name.Contains($grpControlFullPerm))
                                        {
                                         $WebGroupPermissions += $RoleDefinition.Name +";"
                                         # Send the Data to report generated directory
                                          "$($site.Url) `t $($site.Title) `t $sizeinMB `t $($sitesize.ContentDatabase.Name) `t $($WebRoleAssignment.Member.Name) `t $($WebGroupPermissions) `t $($user.LoginName)" | Out-File $FileUrl -Append
                                        }
                                                                       
                                 }
                          write-host "Group has these permissions: " $WebGroupPermissions
                        }
                   }
                }
         }
     }

No comments:

Post a Comment