RSS

Category Archives: PowerShell

Cleanup document versioning in SharePoint 2007

Customers always would like to keep store their all document versions but they don’t know how much space would take to keep storing the versions on the document.Document versions are always a bottleneck for the SharePoint administrators interms of sizing the quota limit.

Mike Mukalian had written an excellent powershell script to delete all the versions of document/files in the document library. For more information, please take a look at his blog entry.

http://www.mukalian.com/blog/post/2011/04/10/PowerShell-Script-to-Delete-All-Versions-in-a-Document-Library.aspx

Also, SP administrators would always like to automate this operation on a periodical schedule. In order to do that,  1. Create a scheduled task to run the script nightly/your own schedule and configure Powershell permissions on the server (run Set-ExecutionPolicy RemoteSigned from a Powershell prompt).

 

Advertisements
 
Leave a comment

Posted by on August 13, 2012 in PowerShell, Sharepoint

 

Using PowerShell list SharePoint site users, roles, groups on all sites

I have been asked to generate the list of users with their roles and groups belongs to for all sites presented in the web application. I found some blog talking about same requirements. But it is not fully satisfied my requirements. So I have taken his logic and created the PowerShell script to list the users, their roles and groups belong for the sites presented in the web application

Here is the below code which will iterate all sites and enumerate the users with their roles and groups belongs to.

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”) > $null
function EnumerateUserRolesPermissions ([string]$webURL){
$site = new-object Microsoft.SharePoint.SPSite($webURL)
$web = $site.OpenWeb()
$webUsers = $web.Users
$groups = $web.sitegroups
foreach($webUser in $webUsers){
$Permissions = $web.Permissions
foreach($group in $groups)
{
foreach($Permission in $Permissions){
if($webUser.ID -eq $Permission.Member.ID){
foreach ($role in $webUser.Roles){
if ($role.Type -ne [Microsoft.SharePoint.SPRoleType]::None)
{
write-host $webURL,“;“,$webUser.LoginName,“;“,$webUser.Name,“;",$role.Type.ToString(),";",$webUser.groups
}
}
}
if($group.ID -eq $Permission.Member.ID){
foreach ($role in $group.Roles){
if ($role.Type -ne [Microsoft.SharePoint.SPRoleType]::None
{
foreach($user in $group.users){
write-host $webURL,“;“,$user.LoginName,“;“,$user.Name,“;",$role.Type.ToString(),";",$group.name
}
}
}
}
}
}
}
}
function EnumerateSiteUsers ()
{
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
foreach ($spService in $farm.Services) {
if (!($spService -is [Microsoft.SharePoint.Administration.SPWebService])) {
continue;
}
foreach ($webApp in $spService.WebApplications) {
if ($webApp -is [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]) { continue }
$webAppUrl = $webApp.GetResponseUri('Default').AbsoluteUri
foreach ($site in $webApp.Sites) {
foreach ($web in $site.AllWebs) {
EnumerateUserRolesPermissions $web.url
}
}
}
}
}

Hope this helps

 
14 Comments

Posted by on February 3, 2011 in PowerShell, Sharepoint

 

Tags: ,