Skip to main content

Get List of Site owners from all web applications in SharePoint using Powershell

List of Site owners from all web applications in SharePoint using Powershell

Add-PSSnapin "Microsoft.SharePoint.Powershell"


function CreateReportObject($url = $null, $title = $null, $desc = $null, $IsRoot = $null, $groupname = $null, $loginname = $null, $dg = $null, $email = $null, $ucount = $null, $created = $null, $farm = $null,$isreadonly = $null) 

$newreportobj = new-object psobject 
        $newreportobj | add-member noteproperty -name "URL" -value $url 
$newreportobj | add-member noteproperty -name "Title" -value $title 
$newreportobj | add-member noteproperty -name "Description" -value $desc 
$newreportobj | add-member noteproperty -name "IsRootWeb" -value $IsRoot 
        $newreportobj | add-member noteproperty -name "Groups" -value $groupname
        $newreportobj | add-member noteproperty -name "Owners" -value $loginname
$newreportobj | add-member noteproperty -name "DomainGroups" -value $dg
$newreportobj | add-member noteproperty -name "Farm" -value $farm
$newreportobj | add-member noteproperty -name "ITO" -value ''
$newreportobj | add-member noteproperty -name "Owners Email" -value $email
$newreportobj | add-member noteproperty -name "Additional Owners" -value ''
$newreportobj | add-member noteproperty -name "User Count" -value $ucount
$newreportobj | add-member noteproperty -name "Created" -value $created 
$newreportobj | add-member noteproperty -name "Is Read-Only" -value $isreadonly
        return ($newreportobj) 
}

#Get all members of the domain group
function GetDomainGroupUsers($web = $null, $domaingroup = $null) 

$_domaingroupusers = "" 
        $reachedMax = $false
$adusers = [Microsoft.SharePoint.Utilities.SPUtility]::GetPrincipalsInGroup($web, $domaingroup, 50, [ref]$reachedMax)
foreach ($aduser in $adusers) 
{
if($aduser.Email -ne '' -AND $aduser.LoginName -like '*i:0#.w*') { $_domaingroupusers += "$($aduser.LoginName);" }
}
        return ($_domaingroupusers) 
}

$global:_Loginname = ""
$global:_dg = ""
$global:_email = ""

#Add all users to the "user" variable
function AddUsers($user) 

if($user.Email -ne '' -AND $user.LoginName -like '*i:0#.w*') { 
if($global:_Loginname -notlike "*$($user.LoginName);*")
{
$global:_Loginname += "$($user.LoginName);" 
$global:_email += "$($user.Email);"
}
}
else { 
if($user.IsDomainGroup -eq 'True') { 
if($global:_dg -notlike "*$($user.Name);*")
{
$global:_dg += "$($user.Name);" 
}

}
}

$fName = [System.IO.Path]::GetRandomFileName() + ".csv"

$ReportPath =".\" + $fName; 

$SiteReportCollection= @() 


$SiteReportCollection+=CreateReportObject -url $date -title '' -desc '' -IsRoot '' -groupname '' -loginname '' -dg '' -email '' -ucount '' -created '' -farm '' -isreadonly ''

$WebAppUrls = "http://webapplication1.com;http://webapplication2.com"

$WebApps = $WebAppUrls.split(";")

foreach($WebApp in $WebApps){

if($WebApp){

$_farm = ""

$webs = Get-SPWebApplication $WebApp | Get-SPSite -Limit All | Get-SPWeb -Limit All | where { $_.IsAppWeb -ne 'True' }
  
#Iterate through all the sub sites except the app web
foreach($web in $webs){

$webGroups = $web.Groups;   
$_IsRootWeb = $web.IsRootWeb
$_Groups = ""
$global:_Loginname = ""
$global:_dg = ""
$global:_email = ""
$_usercount = $web.Users.Count

foreach($webGroup in $webGroups)
{
$_usercount += $webGroup.Users.Count
}

#Get all the users and groups having FULLMASK BasePermission 
foreach($rAssignment in $web.RoleAssignments)
{

foreach($roleDefinition in $rAssignment.RoleDefinitionBindings | Where {$_.BasePermissions -eq [Microsoft.SharePoint.SPBasePermissions]::FullMask})
{
$member = $rAssignment.Member

if($member.GetType() -eq [Microsoft.SharePoint.SPUser])
{
AddUsers $member
}
else
{
if($member.GetType() -eq [Microsoft.SharePoint.SPGroup])
{
foreach ($user in $member.Users) 
{
AddUsers $user
}

$_Groups += "$($member.Name);"
}
}

}

}

#Get all the users from groups having full control or owner permission
foreach($mywebGroup in $webGroups |  foreach { $Groups = $_; $_ } | where {$_.Roles -like '*owner*'} )
{
foreach ($user in $mywebGroup.Users) 
{
AddUsers $user
}

$_Groups += "$($mywebGroup.Name);"
}

#Get all the full control users directly added to the site
foreach($user in $web.Users | foreach { $users = $_; $_ } | where {$_.Roles -like '*owner*'})

AddUsers $user


$SiteReportCollection += CreateReportObject -url $web.Url -title $web.Title -desc $web.Description -IsRoot $_IsRootWeb -groupname $_Groups -loginname $global:_Loginname -dg $global:_dg -email $global:_email -ucount $_usercount -created $web.Created -farm $_farm -isreadonly $web.Site.ReadOnly

$web.Dispose();
}

}
  
}
  
$SiteReportCollection+=CreateReportObject -url $date -title '' -desc '' -IsRoot '' -groupname '' -loginname '' -dg '' -email '' -ucount '' -created '' -farm '' -isreadonly ''

$SiteReportCollection | export-csv $ReportPath -notypeinformation

Write-host "SharePoint site owners data is exported to a CSV file at:"$ReportPath -ForegroundColor Green 

Write-Host "Press any key to continue ..."


$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

Comments

Popular posts from this blog

Tab Control in Asp.Net

Scenerio: I need your help in designing tab control in   asp.net .My requirement is I need a tab control in   asp.net (C#) like  for example goto my computer ,right click c drive and select properties.we get tabs like general,security etc....... like that i need to design one tab control(no need of any rightclick) in my web page and the database table columns should come as tabs and inseide the tab data of that particular column should come.   Example:Employee master tab1:Employee name.........his name in the tab tab2:Age.............his age tab3:Address........his address   Solution:   You can do this using a simple div <style type="text/css"> .tabs         {             position: relative;             height: 20px;             margin: 0;   ...

AI and Microsoft: Revolutionizing Efficiency in Nonprofit Organizations

  How AI and Microsoft Enhance Efficiency in Nonprofit Organizations In today’s fast-paced world, nonprofit organizations face unique challenges—limited resources, increasing demands, and the constant need to do more with less. But what if technology could be the game-changer they need? In my latest research paper,  "How AI and Microsoft Enhance Efficiency in Nonprofit Organizations" , I explore how cutting-edge technologies like Artificial Intelligence (AI) and Microsoft’s innovative tools are revolutionizing the way nonprofits operate. From streamlining administrative tasks to enhancing donor engagement and optimizing resource allocation, AI and Microsoft’s solutions are empowering nonprofits to focus on what truly matters—their mission. This paper dives deep into real-world examples, practical applications, and the transformative potential of these technologies. Whether you’re a nonprofit professional, a tech enthusiast, or simply curious about the intersection of technolo...

Social tagging overview in Sharepoint 2010

A tag is a word or phrase that identifies an individual piece of information according to a set of attributes or criteria. Tags make it easy to find and share information about a specific subject or task. Social tagging helps users categorize information in ways that are meaningful to them. Social tagging can improve the quality of search results by filtering against specific tags, and it can also connect individuals who want to share information with other users who have like interests. This article describes the social tagging features in Microsoft SharePoint Server 2010. This article does not describe how to configure social tagging features. It also does not discuss how to implement social tagging features as part of an overall social media strategy for an enterprise. About using social tagging features Social tagging features help users to share information and to retrieve relevant, high-quality content more efficiently. Such sharing encourages collaboration and b...