<#
******------------------------------------------------------------------------------------------------------------------------------******
Author -> Shiv Mangal Singh
Date -> 18th Feb - 2017
Description -> This Script will generate a report of size of all sites/ sub sites with Full Control users permission from Multiple Site Collection with Site URL, Title Site's Size,
Permission Type, Permission and Login Name details.
Site Collection Name --> $SiteColl = Get-Content "D:\contosoMW_Team\Shiv\PS\SiteColl_SubSites.txt" | Read All Site Collections name from SiteColl_SubSites.txt file
# Report generated directory name / Report location
$FileUrl =$currentdir +"\"+ "Sites_Size_Report_" +$currentdatetime+ ".CSV"
******------------------------------------------------------------------------------------------------------------------------------******
#>
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
# Read All Site Collections name from SiteColl_SubSites.txt file
$SiteColl = Get-Content "D:\contosoMW_Team\Shiv\PS\SiteColl_SubSites.txt"
#set location for report
Set-Location "D:\contosoMW_Team\Shiv\PS"
$currentdir =Convert-Path(Get-Location -PSProvider filesystem)
# get current date
$currentdatetime = Get-Date -Format "yyyy-MM-dd.hh-mm-ss"
# File directory for report
$FileUrl =$currentdir +"\"+ "Sites_Size_Report_" +$currentdatetime+ ".CSV"
#Write CSV- TAB Separated File) Header
"URL `t Title `t Size in MB `t PermissionType `t Permissions `t LoginName" | Out-File $FileUrl
#Loop throuh all Site collection level
foreach($sitename in $SiteColl)
{
$site = Get-SPSite $sitename
# Start Calculate Folder Size
Function CalculateFolderSize($Folder)
{
[long]$FolderSize = 0
foreach ($File in $Folder.Files)
{
#Get File Size
$FolderSize += $file.TotalLength;
#Get the Versions Size
foreach ($FileVersion in $File.Versions)
{
$FolderSize += $FileVersion.Size
}
}
#Iterate through all subfolders
foreach ($SubFolder in $Folder.SubFolders)
{
#Call the function recursively
$FolderSize += CalculateFolderSize $SubFolder
}
return $FolderSize
}
# End calculate Folder name
#Loop throuh all Sub Sites
foreach($Web in $site.AllWebs)
{
#
#Call function to calculate Folder Size
[long]$WebSize = CalculateFolderSize($Web.RootFolder)
#Get Recycle Bin Size
foreach($RecycleBinItem in $Web.RecycleBin)
{
$WebSize += $RecycleBinItem.Size
}
$sizeinMB=$WebSize/1024/1024
$Size = [Math]::Round($sizeinMB, 2)
Write-Host $web.Url ":`t" $Size "MB"
#Iterate through all SPRoleAssignments on the web
foreach($WebRoleAssignment in $Web.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 Filedirectory/Report file
"$($Web.Url) `t $($Web.Title)`t $Size `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": We have 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 Filedirectory/Report file
"$($Web.Url) `t $($Web.Title) `t $Size `t $($WebRoleAssignment.Member.Name) `t $($WebGroupPermissions) `t $($user.LoginName)" | Out-File $FileUrl -Append
}
}
write-host "Group has these permissions: " $WebGroupPermissions
}
}
}
}
}
******------------------------------------------------------------------------------------------------------------------------------******
Author -> Shiv Mangal Singh
Date -> 18th Feb - 2017
Description -> This Script will generate a report of size of all sites/ sub sites with Full Control users permission from Multiple Site Collection with Site URL, Title Site's Size,
Permission Type, Permission and Login Name details.
Site Collection Name --> $SiteColl = Get-Content "D:\contosoMW_Team\Shiv\PS\SiteColl_SubSites.txt" | Read All Site Collections name from SiteColl_SubSites.txt file
# Report generated directory name / Report location
$FileUrl =$currentdir +"\"+ "Sites_Size_Report_" +$currentdatetime+ ".CSV"
******------------------------------------------------------------------------------------------------------------------------------******
#>
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
# Read All Site Collections name from SiteColl_SubSites.txt file
$SiteColl = Get-Content "D:\contosoMW_Team\Shiv\PS\SiteColl_SubSites.txt"
#set location for report
Set-Location "D:\contosoMW_Team\Shiv\PS"
$currentdir =Convert-Path(Get-Location -PSProvider filesystem)
# get current date
$currentdatetime = Get-Date -Format "yyyy-MM-dd.hh-mm-ss"
# File directory for report
$FileUrl =$currentdir +"\"+ "Sites_Size_Report_" +$currentdatetime+ ".CSV"
#Write CSV- TAB Separated File) Header
"URL `t Title `t Size in MB `t PermissionType `t Permissions `t LoginName" | Out-File $FileUrl
#Loop throuh all Site collection level
foreach($sitename in $SiteColl)
{
$site = Get-SPSite $sitename
# Start Calculate Folder Size
Function CalculateFolderSize($Folder)
{
[long]$FolderSize = 0
foreach ($File in $Folder.Files)
{
#Get File Size
$FolderSize += $file.TotalLength;
#Get the Versions Size
foreach ($FileVersion in $File.Versions)
{
$FolderSize += $FileVersion.Size
}
}
#Iterate through all subfolders
foreach ($SubFolder in $Folder.SubFolders)
{
#Call the function recursively
$FolderSize += CalculateFolderSize $SubFolder
}
return $FolderSize
}
# End calculate Folder name
#Loop throuh all Sub Sites
foreach($Web in $site.AllWebs)
{
#
#Call function to calculate Folder Size
[long]$WebSize = CalculateFolderSize($Web.RootFolder)
#Get Recycle Bin Size
foreach($RecycleBinItem in $Web.RecycleBin)
{
$WebSize += $RecycleBinItem.Size
}
$sizeinMB=$WebSize/1024/1024
$Size = [Math]::Round($sizeinMB, 2)
Write-Host $web.Url ":`t" $Size "MB"
#Iterate through all SPRoleAssignments on the web
foreach($WebRoleAssignment in $Web.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 Filedirectory/Report file
"$($Web.Url) `t $($Web.Title)`t $Size `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": We have 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 Filedirectory/Report file
"$($Web.Url) `t $($Web.Title) `t $Size `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