fachinformatiker-wiki

it's easy when it's here

User Tools

Site Tools


microsoft:sharepoint2016:powershell-scripts

SharePoint Powershell Scripts

Get all users and groups

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
 
try
{
 
       $objSiteColl = Get-SPSite http://portal.local
       "Site Name`tGroup Name`tUser Name"
       foreach ($objWeb in $objSiteColl.AllWebs)
       {
              write-host -foregroundcolor yellow "`nWorking on web:" $objWeb.Title
              foreach ($objGrp in $objWeb.groups)
              {
                     $grpName = $objGrp.name
                     write-host "`nGroup Name: " $grpName  -foregroundcolor green
                     foreach ($objUser in $objGrp.users)
                     {
                            $objWeb.Title + "`t" + $objGrp.name +"`t"+ $objUser.name
                            write-host "Login-ID:: " $objUser.UserLogin  -foregroundcolor red
                     }
              }
       }
}
 
catch
{
       Write-Host "`nError:: $($_.Exception.Message)" -foregroundcolor red -BackgroundColor Yellow
}

Get all Groups in a Site Collection

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
 
{
            Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
 
$SPFile = ".\GetGroupInformation.txt"
$SPSiteUrl = Read-Host "Enter the Url of the Site Collection "
$SPSite = Get-SPSite $SPSiteUrl -ErrorAction SilentlyContinue
 
if($SPSite -ne $null)
{
    $SPWebCollection = $SPSite.AllWebs
    foreach($SPWeb in $SPWebCollection)
    {
        Write-Output $SPWeb.Title "contains the following groups"| Out-File $SPFile -append
        Write-Output "========================"| Out-File $SPFile -append
        foreach($SPGroup in $SPWeb.Groups)
        {
            Write-Output $SPGroup.Name| Out-File $SPFile -append
        }
        Write-Output "========================"| Out-File $SPFile -append
    }
}
 
else
{
Write-Host "Requested Site Could Not be found" -ForegroundColor DarkRed
}
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.  More information about cookies 
microsoft/sharepoint2016/powershell-scripts.txt · Last modified: 2024/02/17 19:03 by 127.0.0.1