Skip to content
edwardramos.com

Be the song that you here in your head

edwardramos.com

Be the song that you here in your head

  • Home
  • About
  • About
  • Donate
  • Resume
  • Home
  • About
  • About
  • Donate
  • Resume
Close

Search

Subscribe
My WorkTech

Inventory Permissions with Powershell

By edwardramos
February 5, 2015 2 Min Read
0

Here is a script that will inventory all users and permissions by site collection in a sharepoint farm to a csv file and/or a SharePoint list.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#update these variables as needed
$scriptname = "siteusers"
$FilePath = "d:\dashboard\eer-siteusers.csv"
$docliburl= "http://eer/spd/IT/systems/ws/dashboard/Lists/siteusers";

function eer-$scriptname() {
    [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 }

            foreach ($site in $webApp.Sites) {

foreach ($web in $site.AllWebs) {
if (($web.permissions -ne $null) -and ($web.hasuniqueroleassignments -eq "True")) {
foreach  ($group in $web.Groups) {
foreach ($user in $group.users) { 
$data = @{
                                "loginname" = $user.loginname
								"WebUrl" = $web.url
								"GroupPermission" = $group.permission
								"UserGroup" = $group
								"SiteOwner" = $web.description
								"SiteName" = $web.title
							   }
                            New-Object PSObject -Property $data
     }}
    }
	}
   }
 } 
 $web.Dispose()
}
$site.Dispose()
}    	

#eer-$scriptname | Out-GridView
eer-$scriptname | Export-Csv -Path $FilePath -NoTypeInformation

$site=new-object Microsoft.SharePoint.SPSite($docliburl);
$web=$site.openweb();
$list=$web.GetList($docliburl);

###delete old items

$collListItems = $List.Items; 
$count = $collListItems.Count - 1 
for($intIndex = $count; $intIndex -gt -1; $intIndex--) 
{ 
        $collListItems.Delete($intIndex); 
} 

###

$csv_file = Import-Csv $FilePath;
foreach ($line in $csv_file)
{ 
Write-Output $line.Title;
  $item = $list.Items.Add();
  $item["Site"] = $line.WebURL;
  $item["Member"] = $line.LoginName;
  $item["Perms"] = $line.GroupPermission;
  $item["Group"] = $line.UserGroup;
  $item["Site Owner"] = $line.SiteOwner;
  $item["Title"] = $line.SiteName;
  $item.Update();
}




Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#update these variables as needed
$scriptname = "siteusers"
$FilePath = "d:\dashboard\eer-siteusers.csv"
$docliburl= "http://eer/spd/IT/systems/ws/dashboard/Lists/siteusers";

function eer-$scriptname() {
    [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 }

            foreach ($site in $webApp.Sites) {

foreach ($web in $site.AllWebs) {
if (($web.permissions -ne $null) -and ($web.hasuniqueroleassignments -eq "True")) {

foreach ($user in $web.users) { 
$data = @{
                                "loginname" = $user.loginname
								"WebUrl" = $web.url
								"GroupPermission" = $user.permission
							
								"SiteOwner" = $web.description
								"SiteName" = $web.title
							   }
                            New-Object PSObject -Property $data
     }
    }
	}
   }
 } 
 $web.Dispose()
}
$site.Dispose()
}    	

#eer-$scriptname | Out-GridView
eer-$scriptname | Export-Csv -Path $FilePath -NoTypeInformation

$site=new-object Microsoft.SharePoint.SPSite($docliburl);
$web=$site.openweb();
$list=$web.GetList($docliburl);



$csv_file = Import-Csv $FilePath;
foreach ($line in $csv_file)
{ 
Write-Output $line.Title;
  $item = $list.Items.Add();
  $item["Site"] = $line.WebURL;
  $item["Member"] = $line.LoginName;
  $item["Perms"] = $line.GroupPermission;
  $item["Site Owner"] = $line.SiteOwner;
  $item["Title"] = $line.SiteName;
  $item.Update();
}

Tags:

Microsoftpowershell
Author

edwardramos

Follow Me
Other Articles
Previous

Creating SharePoint webparts

Next

Zen and the Art of Motorcycle Maintenance: An Inquiry Into Values

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Why I Still Think Personal Websites Matter
  • What Is Prompt Engineering?
  • Wrap Up: DGR Boston 2025
  • Enable external sharing for Power Bi
  • The Way of Zen

Recent Comments

  1. Edward Ramos on My 360° view at LavaStorm
  2. Milo on My 360° view at LavaStorm
  3. Isaac on Thank You
  4. Isaac on Welcome!
  5. Isaac on My 360° view at LavaStorm

Archives

  • May 2026
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • May 2024
  • April 2024
  • January 2024
  • February 2023
  • September 2022
  • April 2021
  • February 2020
  • August 2019
  • April 2019
  • October 2018
  • January 2018
  • December 2017
  • July 2017
  • January 2017
  • December 2016
  • September 2016
  • August 2016
  • March 2016
  • December 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • February 2015
  • May 2014
  • March 2014
  • February 2014
  • August 2013
  • July 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • November 2012
  • October 2012
  • September 2012
  • July 2012
  • July 2011
  • June 2008
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • January 2007
  • October 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • February 2006
  • December 2005
  • November 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • December 2004
  • October 2004
  • February 2004
  • November 2003
  • October 2002
  • September 2002
  • May 2002
  • January 2002
  • November 2000

Categories

  • Art
  • Automotive
  • Entertainment
  • Food
  • Life
  • My Work
  • Tech
  • Travel

Copyright 2026 — edwardramos.com. All rights reserved. Blogsy WordPress Theme