Tag Archives: powershellscript

All Webs and Site Templates in use within a Site Collection PowerShell Script

$site = Get-SPSite “http://yoursite”

foreach ($web in $site.AllWebs) {

$web | Select-Object -Property Title,Url,WebTemplate




Get list of all users present in a site under different SharePoint Groups


I wanted to see all users who have access to the SharePoint site and belongs to which SharePoint group.


Below SharePoint powershell script helps me to get list of users group wise-

$site = Get-SPSite <Provide Site Collection URL here>
$web = $site.OpenWeb()
$groups = $web.sitegroups
foreach ($grp in $groups) {
    "Group: " + $grp.name;
    $groupName = $grp.name
    write-host "Group: " $groupName   -foregroundcolor green
    foreach ($user in $grp.users) {
            "User: " + $user.name
            write-host "User " $user.UserLogin   -foregroundcolor red


  • Navigate to Script location and type below command-

This will show output on screen.

  • Navigate to Script location and type below command-
GetUsers.ps1 | Out-File C:Output.csv

This will generate output as csv file. “C:Output.csv” is the file name and location where generated csv file is saved. Please change as per your requirement.

Access Requests Explained for SharePoint 2013 – With a Script to Assign Default Groups

One of the features of SharePoint that has been around is the ability for users that need access to a site, and are denied access, through the “Request Access” process.

To enable or review these settings,

  • go to “Settings” > “Site Settings” > “User and Permissions” and click “Access Request Settings”. In the “Access Request Settings” dialog box, select the check box next to “Allow access requests” then provide an email address of the individual you’d like to manage this feature.
  • If a site has multiple groups with the same permission levels (Owners, Members and Viewers) but there is not an assigned default group, then you will see the problem where access requests will either not display for the impacted user or an owner will not be able to approve requests.

Here’s a Windows PowerShell script to change each of the groups for a site so that each is identified as the default group for Members, Owners and Visitors

You’ll need to a the “Microsoft.SharePoint.PowerShell” add-in at the top of the script to get the SharePoint references.

#Members Group
$web = Get-SPWeb “
$groupToMakeDefaultMembersGroup = $web.Groups | ? { $_.Name -eq “Team Site Members” }
$web.AssociatedMemberGroup = $groupToMakeDefaultMembersGroup

#Owners Group
$web = Get-SPWeb “
$groupToMakeDefaultOwnersGroup = $web.Groups | ? { $_.Name -eq “Team Site Owners” }
$web.AssociatedOwnerGroup = $groupToMakeDefaultOwnersGroup

#Visitors Group
$web = Get-SPWeb “
$groupToMakeDefaultVisitorsGroup = $web.Groups | ? { $_.Name -eq “Team Site Visitors” }
$web.AssociatedVisitorGroup = $groupToMakeDefaultMembersGroup

#Enable Access Requests after it was disabled
$web.RequestAccessEmail = “user@mydomain.com”

If you turn off the feature, you will can re-enable the feature by adding an email address to the “RequestAccessEmail” property.

Hope this helps solving the problem around assigning default groups and enabling the Request Access feature in SharePoint 2013.