Powershell help

Hi,

I am using script mentioned below to get a list of users that have access to a particular library. However, this script does not tell how to export the output to a csv and also the permission level that a user has on the library.

https://gallery.technet.microsoft.com/SharePoint-Get-list-of-all-c28c87f9

Please advise.

March 24th, 2015 2:00pm

Hi,

Below link with help you

http://www.sharepointdiary.com/2013/01/permission-report-for-specific-user.html

Try the below script

function GetSPAllSPUsers($SiteCollectionURL,$SPListName)
{
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
    $site = new-object Microsoft.SharePoint.SPSite($SiteCollectionURL)    
    $web = $site.openweb()
    $list = $web.Lists[$SPListName]
    $siteCollUsers = $web.SiteUsers
    
    foreach($user in $siteCollUsers)
        {
            Write-Host " ------------------------------------- "
            Write-Host "Site Collection URL:", $SiteCollectionURL
            if($list.DoesUserHavePermissions([Microsoft.SharePoint.SPBasePermissions]::ViewListItems,$user) -eq $true)
                {
                    Write-Host "User : ", $user.LoginName
                    Write-Host "Assigned Permissions : ", $list.GetUserEffectivePermissions($user.LoginName)
                }            
            Write-Host " ------------------------------------- "        
        }
    
        $web.Dispose()
        $site.Dispose()
 }

GetSPAllSPUsers "http://sp2010:1234" "List Name" | Export-Csv  C:\Users.csv

Free Windows Admin Tool Kit Click here and download it now
March 24th, 2015 2:46pm

sorry did not work...I am also not looking to export for a particular user.
March 24th, 2015 5:16pm

Hi,

Please try the demo below which is created based on Somnaths version:

function GetSPAllSPUsers($SiteCollectionURL,$SPListName) 
{ 
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null 
    $site = new-object Microsoft.SharePoint.SPSite($SiteCollectionURL)     
    $web = $site.openweb() 
    $list = $web.Lists[$SPListName] 
    $siteCollUsers = $web.SiteUsers 

    $collection = @()

    foreach($user in $siteCollUsers) 
    { 
        Write-Host " ------------------------------------- " 
        Write-Host "Site Collection URL:", $SiteCollectionURL 
        if($list.DoesUserHavePermissions([Microsoft.SharePoint.SPBasePermissions]::ViewListItems,$user) -eq $true) 
        { 
            Write-Host "User : ", $user.LoginName 
            Write-Host "Assigned Permissions : ", $list.GetUserEffectivePermissions($user.LoginName) 

            $collection += $user
        }             
        Write-Host " ------------------------------------- "   

    } 

    $web.Dispose() 
    $site.Dispose() 

    $collection | Export-Csv  C:\Users1.csv -NoTypeInformation
} 

GetSPAllSPUsers "http://sp" "List1" 


Thanks         

Patrick Liang

Free Windows Admin Tool Kit Click here and download it now
March 25th, 2015 3:11am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics