<#
******-----------------------------------------------------------------------******
Author -> Shiv Mangal Singh
Date -> 27th Jan - 2017
Description -> This Script will generate Unique Permission details across List & document library level(Folder & nth Level sub folder & Item Level)
Path of csv file->$path = "D:\contosoMW_Team\Shiv\27Jan17\UniquePermissions.csv"
Site Collection Name --> $site = Get-SPSite "https://ms.contoso.net/global/sapcoe/"
******-----------------------------------------------------------------------******
#>
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get Site Name
$web = Get-SPWeb "https://ms.contoso.net/global/treasuryrrp"
$list =$web.GetList("https://ms.contoso.net/global/treasuryrrp/2017%20Resolution%20Plan")
Write-Host $list.Title
#Write Header to CSV File
"Site/List `t Title `t URL" | out-file UniquePermissions.csv
$FileDirectory = "D:\contosoMW_Team\shravan\UniquePermissions.csv"
$permissionLevel ="Full Control"
# You can Pass here User's account with domain name or SharePoint Group Name
$accountName ="r1-core\skumarwa"
if ($accountName.Contains("\"))
{
$account = $Web.EnsureUser($accountName)
}
else
{
$account = $Web.SiteGroups[$accountName]
}
# End for Users account and Group
if (($list.HasUniqueRoleAssignments) -and ($list.Hidden -eq $false))
{
Write-Host $list.Title
$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()
******-----------------------------------------------------------------------******
Author -> Shiv Mangal Singh
Date -> 27th Jan - 2017
Description -> This Script will generate Unique Permission details across List & document library level(Folder & nth Level sub folder & Item Level)
Path of csv file->$path = "D:\contosoMW_Team\Shiv\27Jan17\UniquePermissions.csv"
Site Collection Name --> $site = Get-SPSite "https://ms.contoso.net/global/sapcoe/"
******-----------------------------------------------------------------------******
#>
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get Site Name
$web = Get-SPWeb "https://ms.contoso.net/global/treasuryrrp"
$list =$web.GetList("https://ms.contoso.net/global/treasuryrrp/2017%20Resolution%20Plan")
Write-Host $list.Title
#Write Header to CSV File
"Site/List `t Title `t URL" | out-file UniquePermissions.csv
$FileDirectory = "D:\contosoMW_Team\shravan\UniquePermissions.csv"
$permissionLevel ="Full Control"
# You can Pass here User's account with domain name or SharePoint Group Name
$accountName ="r1-core\skumarwa"
if ($accountName.Contains("\"))
{
$account = $Web.EnsureUser($accountName)
}
else
{
$account = $Web.SiteGroups[$accountName]
}
# End for Users account and Group
if (($list.HasUniqueRoleAssignments) -and ($list.Hidden -eq $false))
{
Write-Host $list.Title
$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()
No comments:
Post a Comment