当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 获取 SharePoint 场 - Web 应用程序 - 网站集 - 网站的所有用户

作者:精品下载站 日期:2024-12-15 00:01:16 浏览:15 分类:玩电脑

使用 PowerShell 获取 SharePoint 场 - Web 应用程序 - 网站集 - 网站的所有用户


要求:获取 SharePoint Farm 的所有用户。

[玩转系统] 使用 PowerShell 获取 SharePoint 场 - Web 应用程序 - 网站集 - 网站的所有用户

SharePoint PowerShell 获取场中的所有用户

您想要获取 SharePoint 场中所有用户的列表吗? PowerShell 可以帮助您!这篇博文将向您展示如何使用 PowerShell 快速查找 SharePoint 场中的所有用户。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Output Report File
$currentLocation = (Get-Location).Path
$outputReport = $currentLocation + "\" + "SharePointUsers.csv" 
#Write CSV File Header

#Array to hold user data
$UserDataCollection = @() 

#Get All Web Applications and iterate through
$WebAppsColl = Get-SPWebApplication 
#To Get all Users from specific web application, Use: $WeAppsColl = Get-SPWebApplication "web-app-url"
#and remove line #12
 
foreach($WebApp in $WebAppsColl)
{
    Write-host "Scanning Web Application:"$WebApp.Name
    #Get All site collections and iterate through
    $SitesColl = $WebApp.Sites
    #To Get all Users from site collection, Use: $SitesColl = Get-SPSite "site-collection-url"
    #and remove lines between #11 to #20 and Line #55 "}"
    #get all users from site collection PowerShell
    foreach ($Site in $SitesColl) 
    {
        Write-host "Scanning Site Collection:"$Site.URL
        #Get All Webs and iterate through
        $WebsColl = $Site.AllWebs
        #To Get all Users from aq site, Use: $WebsColl = Get-SPWeb "web-url"
         #and remove lines between #11 to #28 and Lines #53, #54, #55 "}"

            foreach ($web in $WebsColl) 
            {
                Write-host "Scanning Web:"$Web.URL
                #Get All Users of the Web
                $UsersColl = $web.AllUsers  #get all users programmatically 
                    #list all users 
                    foreach ($user in $UsersColl) 
                    {
                           if($User.IsDomainGroup -eq $false) 
                            {
                                $UserData = New-Object PSObject
              
                                $UserData | Add-Member -type NoteProperty -name "UserLogin" -value $user.UserLogin.ToString()
                                $UserData | Add-Member -type NoteProperty -name "DisplayName" -value $user.displayName.ToString()
                                $UserData | Add-Member -type NoteProperty -name "E-mailID" -value $user.Email.ToString()

                                $UserDataCollection += $UserData
                            }
                    }
            $Web.dispose()
            }
         $site.dispose()
        }
    }    
#Remove duplicates
$UserDataCollection = $UserDataCollection | sort-object -Property  {$_.UserLogin } -Unique 

#Remove duplicates and export all users to excel
$UserDataCollection | Export-Csv -LiteralPath $OutputReport -NoTypeInformation
Write-host "Total Number of Unique Users found:"$UserDataCollection.Length

该脚本可用于获取网站集中的所有用户并将所有用户导出到 Excel。

使用 PowerShell 获取 SharePoint 场中的所有唯一用户:

一个用于获取 SharePoint 场的唯一用户的衬垫 PowerShell 脚本:


Get-SPSite -Limit All | Select -ExpandProperty AllWebs | select -ExpandProperty AllUsers | ? {$_.IsDomainGroup -ne $true} |  select -Unique LoginName

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯