When you need details about multiple SharePoint sites at once, including their URLs, owners, storage usage and permissions, then running a PowerShell script is the easier and faster option. Let us find out how you can get SharePoint site information with PowerShell scripts.
The Get-SPSite cmdlet is the key cmdlet that is used by developers to get information about SharePoint site collections.
This cmdlet either returns a single site that matches the identify parameter that you set or returns all the sites that match the Filter parameter.
It can be set with the following scopes
If you don’t set any parameters, the scope is the farm, by default. Here is an example:
Get-SPSite ‘https://<site name>’ | Get-SPWeb -Limit All | Select Title
This command will fetch the collection of the subweb titles that are in the site collection at https://<site name>
Now, let us look at some of the other PowerShell commands that you can run when it comes to getting SharePoint information.
Let us look at how you can get information about specific site properties like site owner, storage usage, maximum quota level and last content modified date.
To do that you will need to Select-Object parameter in the PowerShell script. Here is how you can do it:
Get-SPSite “http://sharepoint/sites/ent" | Select-Object url, owner, @{Expression={$_.Usage.Storage}}, @{Expression={$_.Audit.AuditFlags}}, readonly, LastContentModifiedDate, @{Express={$_.QuotaStorageMaximumLevel}}
The above command will return the site owner, storage usage, and the last date on which the document is modified.
Let us now look at how you can export the SharePoint site information to a .csv file. Here is the PowerShelll script that you should run
Get-SPWebApplication http://sharepoint/ | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select Title, URL, ID, ParentWebID | Export-CSV C:rootsharepointinventory.csv -NoTypeInformation
The above command will extract the site information and save it in an .csv file titled C:rootsharepointinventory.csv
Get Information on the Groups and Members of a SharePoint Site
If you need information of the groups and users for a specific SharePoint site, you can use the Get-SPSite cmdlet as well. Here is the script to run:
$site = Get-SPSite http://sharepoint/sites/ent/
$groups = $site.RootWeb.sitegroups
foreach ($grp in $groups) {"Group: " + $grp.name; foreach ($user in $grp.users) {" User: " + $user.name} }
$site.Dispose()
If you need a complete permissions report for a SharePoint site, you need to run the following code. Make sure that specify the SharePoint site URL ($SPSiteURL) as well as the path to export the data to a csv file ($ExportFile) :
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$SPSiteUrl = "http://sharepoint/sites/ent"
$SPSite = New-Object Microsoft.SharePoint.SPSite($SPSiteUrl);
$ExportFile = "C:rootPermissions.csv"
“Web Title,Web URL,List Title,User or Group,Role,Inherited" | out-file $ExportFile
foreach ($WebPath in $SPSite.AllWebs)
{
if ($WebPath.HasUniqueRoleAssignments)
{
$SPRoles = $WebPath.RoleAssignments;
foreach ($SPRole in $SPRoles)
{
foreach ($SPRoleDefinition in $SPRole.RoleDefinitionBindings)
{
$WebPath.Title + "," + $WebPath.Url + "," + "N/A" + "," + $SPRole.Member.Name + "," + $SPRoleDefinition.Name + "," + $WebPath.HasUniqueRoleAssignments | out-file $ExportFile -append
}
}
}
foreach ($List in $WebPath.Lists)
{
if ($List.HasUniqueRoleAssignments)
{
$SPRoles = $List.RoleAssignments;
foreach ($SPRole in $SPRoles)
{
foreach ($SPRoleDefinition in $SPRole.RoleDefinitionBindings)
{
$WebPath.Title + "," + $WebPath.Url + "," + $List.Title + "," + $SPRole.Member.Name + "," + $SPRoleDefinition.Name | out-file $ExportFile -append
}
}
}
}
}
$SPSite.Dispose();
Are you facing technical issues with your SharePoint environment but don’t know how to solve them? Get expert support from our certified SharePoint developers and ensure optimum performance from your SharePoint system.
Boost SharePoint Performance – Contact Our SharePoint Developers