<#
******-----------------------------------------------------------------------******
Author -> Shiv Mangal Singh
Date -> 27th Jan - 2017
Description -> This Script will generate Unique Permission details across Site Collection level(Sub site, Document Library, List, Folder, Item level)
-> Also You can grant Users and SharePoint Group respective Permission wherever unique permission exists in Site collection Level
Path of csv file->$path = "D:\ContososMW_Team\Shiv\27Jan17\UniquePermissions.csv"
Site Collection Name --> $site = Get-SPSite "https://ms.contoso.net/global/abc/"
******-----------------------------------------------------------------------******
#>
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get Site Name
$site = Get-SPSite "https://ms.contosos.net/global/abc/
Write-Host $site.Url
#Write Header to CSV File
"Site/List `t Title `t URL" | out-file UniquePermissions.csv
$FileDirectory = "D:\contosoMW_Team\Shiv\27Jan17\UniquePermissions_27.csv"
$permissionLevel ="Contribute"
# You can Pass here User's account with domain name or SharePoint Group Name
$accountName ="r7-core\adelossa"
foreach ($web in $site.AllWebs)
{
if ($accountName.Contains("\"))
{
$account = $Web.EnsureUser($accountName)
}
else
{
$account = $Web.SiteGroups[$accountName]
}
if ( ($web.HasUniqueRoleAssignments) -and ($web.IsRootWeb -eq $false))
{
$result ="Site `t $($web.Title) `t $($web.Url)"
$result | Out-File $FileDirectory -Append
#You can get the permissions applied by: $web.permissions | format-list member, basepermissions
# To grant group permission on List level
try
{
$roleAssignemnet =New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$roldefinition = $web.RoleDefinitions[$permissionLevel]
$roleAssignemnet.RoleDefinitionBindings.Add($roldefinition)
$web.RoleAssignments.Add($roleAssignemnet)
$web.Update();
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}
#End group permission on Web level
}
foreach ($list in $web.Lists)
{
if (($list.HasUniqueRoleAssignments) -and ($list.Hidden -eq $false))
{
$result= "List `t $($list.Title) `t $($web.Url +"/"+$list.Url)"
$result | Out-File $FileDirectory -Append
# To grant group permission on List level
try
{
#$roleAssignemnet =New-Object Microsoft.SharePoint.SPRoleAssignment($grp)
$roleAssignemnet =New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$roldefinition = $web.RoleDefinitions[$permissionLevel]
$roleAssignemnet.RoleDefinitionBindings.Add($roldefinition)
$list.RoleAssignments.Add($roleAssignemnet)
$list.Update();
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}
# End group permission on list level
}
#Loop through each Item in the List
foreach($item in $list.items)
{
if($item.HasUniqueRoleAssignments -eq $true)
{
Write-Host $item.Url
$result= "Item `t $($item.Title) `t $($web.Url +"/"+$item.Url)"
$result | Out-File $FileDirectory -Append
# To grant group permission on Item level
try
{
$roleAssignemnet =New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$roldefinition = $web.RoleDefinitions[$permissionLevel]
$roleAssignemnet.RoleDefinitionBindings.Add($roldefinition)
$item.RoleAssignments.Add($roleAssignemnet)
$item.Update();
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}
# End group permission on Item level
}
}
#End Each Item Loops
#Loop through each Folder in the List
foreach($folder in $list.Folders)
{
if($folder.HasUniqueRoleAssignments -eq $true)
{
Write-Host $folder.Url
$result = "Folder `t $($folder.Title) `t $($web.Url +"/"+$list.Url+$folder.Url)"
$result | Out-File $FileDirectory -Append
# To grant group permission on folder level
try
{
$roleAssignemnet =New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$roldefinition = $web.RoleDefinitions[$permissionLevel]
$roleAssignemnet.RoleDefinitionBindings.Add($roldefinition)
$folder.RoleAssignments.Add($roleAssignemnet)
$folder.Update();
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}# End group permission on folder level# End group permission on folder level
}
}#Loop through each Folder in the List
}
$web.Dispose()
}
$site.Dispose()
******-----------------------------------------------------------------------******
Author -> Shiv Mangal Singh
Date -> 27th Jan - 2017
Description -> This Script will generate Unique Permission details across Site Collection level(Sub site, Document Library, List, Folder, Item level)
-> Also You can grant Users and SharePoint Group respective Permission wherever unique permission exists in Site collection Level
Path of csv file->$path = "D:\ContososMW_Team\Shiv\27Jan17\UniquePermissions.csv"
Site Collection Name --> $site = Get-SPSite "https://ms.contoso.net/global/abc/"
******-----------------------------------------------------------------------******
#>
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get Site Name
$site = Get-SPSite "https://ms.contosos.net/global/abc/
Write-Host $site.Url
#Write Header to CSV File
"Site/List `t Title `t URL" | out-file UniquePermissions.csv
$FileDirectory = "D:\contosoMW_Team\Shiv\27Jan17\UniquePermissions_27.csv"
$permissionLevel ="Contribute"
# You can Pass here User's account with domain name or SharePoint Group Name
$accountName ="r7-core\adelossa"
foreach ($web in $site.AllWebs)
{
if ($accountName.Contains("\"))
{
$account = $Web.EnsureUser($accountName)
}
else
{
$account = $Web.SiteGroups[$accountName]
}
if ( ($web.HasUniqueRoleAssignments) -and ($web.IsRootWeb -eq $false))
{
$result ="Site `t $($web.Title) `t $($web.Url)"
$result | Out-File $FileDirectory -Append
#You can get the permissions applied by: $web.permissions | format-list member, basepermissions
# To grant group permission on List level
try
{
$roleAssignemnet =New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$roldefinition = $web.RoleDefinitions[$permissionLevel]
$roleAssignemnet.RoleDefinitionBindings.Add($roldefinition)
$web.RoleAssignments.Add($roleAssignemnet)
$web.Update();
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}
#End group permission on Web level
}
foreach ($list in $web.Lists)
{
if (($list.HasUniqueRoleAssignments) -and ($list.Hidden -eq $false))
{
$result= "List `t $($list.Title) `t $($web.Url +"/"+$list.Url)"
$result | Out-File $FileDirectory -Append
# To grant group permission on List level
try
{
#$roleAssignemnet =New-Object Microsoft.SharePoint.SPRoleAssignment($grp)
$roleAssignemnet =New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$roldefinition = $web.RoleDefinitions[$permissionLevel]
$roleAssignemnet.RoleDefinitionBindings.Add($roldefinition)
$list.RoleAssignments.Add($roleAssignemnet)
$list.Update();
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}
# End group permission on list level
}
#Loop through each Item in the List
foreach($item in $list.items)
{
if($item.HasUniqueRoleAssignments -eq $true)
{
Write-Host $item.Url
$result= "Item `t $($item.Title) `t $($web.Url +"/"+$item.Url)"
$result | Out-File $FileDirectory -Append
# To grant group permission on Item level
try
{
$roleAssignemnet =New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$roldefinition = $web.RoleDefinitions[$permissionLevel]
$roleAssignemnet.RoleDefinitionBindings.Add($roldefinition)
$item.RoleAssignments.Add($roleAssignemnet)
$item.Update();
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}
# End group permission on Item level
}
}
#End Each Item Loops
#Loop through each Folder in the List
foreach($folder in $list.Folders)
{
if($folder.HasUniqueRoleAssignments -eq $true)
{
Write-Host $folder.Url
$result = "Folder `t $($folder.Title) `t $($web.Url +"/"+$list.Url+$folder.Url)"
$result | Out-File $FileDirectory -Append
# To grant group permission on folder level
try
{
$roleAssignemnet =New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$roldefinition = $web.RoleDefinitions[$permissionLevel]
$roleAssignemnet.RoleDefinitionBindings.Add($roldefinition)
$folder.RoleAssignments.Add($roleAssignemnet)
$folder.Update();
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}# End group permission on folder level# End group permission on folder level
}
}#Loop through each Folder in the List
}
$web.Dispose()
}
$site.Dispose()
No comments:
Post a Comment