简体   繁体   English

从 SharePoint 和 PowerShell 获取用户详细信息

[英]Get user details from SharePoint with PowerShell

I'm using this PowerShell script to get site owners:我正在使用这个 PowerShell 脚本来获取网站所有者:

$siteUrl = Read-Host "enter site url here:"

$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)

$spWebApp = $rootSite.WebApplication

foreach($site in $spWebApp.Sites)

{

    foreach($siteAdmin in $site.RootWeb.SiteAdministrators)

    {

        Write-Host "$($siteAdmin.ParentWeb.Url) - $($siteAdmin.DisplayName)"

    }

    $site.Dispose()
}

$rootSite.Dispose()

I want that it will print some details of the site owner like phone number and email.我希望它会打印网站所有者的一些详细信息,例如电话号码和 email。 How can I achieve that?我怎样才能做到这一点?

You have two choices I think.我认为你有两个选择。 Access the SPUser properties or get information from active directory.访问SPUser属性或从活动目录中获取信息。

In the first case, are you not able to access the properties as you did for DisplayName ?在第一种情况下,您是否无法像对DisplayName那样访问属性? I mean if you have a SPUser object to get the email just use:我的意思是,如果您有一个SPUser object 来获得 email,只需使用:

 write-output "$($siteAdmin.Email)"

For information about to get the user properties from active directory, you can easily implement the solution provided in the following question .有关从活动目录获取用户属性的信息,您可以轻松实施以下问题中提供的解决方案。 It worked fine for me.它对我来说很好。

Hope this helps希望这可以帮助


EDIT with improvement编辑改进

Standing from MS Documentation you have some properties avaialble, see SPUSer Members .站在 MS 文档中,您有一些可用的属性,请参阅SUSer Members FOr example you have not phone .例如,您没有phone

To get something from the active directory try to change the following function so that it returns the attributes you need (tested on windows 2k8 server):要从活动目录中获取某些内容,请尝试更改以下 function 以便它返回您需要的属性(在 windows 2k8 服务器上测试):

function Get-AD-Data {
    $strFilter = "(&(objectCategory=User))"
    $objDomain = New-Object System.DirectoryServices.DirectoryEntry
    $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
    $objSearcher.SearchRoot = $objDomain
    $objSearcher.PageSize = 1000
    $objSearcher.Filter = $strFilter
    $objSearcher.SearchScope = "Subtree"
    $objSearcher.FindAll() | select @{L="User";E={$_.properties.displayname}},
    @{L="Department";E={$_.properties.department}},
    @{L="MemberOf";E={$_.properties.memberof}}    
}

This function returns all users from AD along with the selected attributes.此 function 从 AD 返回所有用户以及选定的属性。 To get information from a specific user you would use (I guess):要从特定用户那里获取信息,您将使用(我猜):

$ad_userdetails = Get-AD-Data | ? {$_.user -eq $siteAdmin.Name}

Cheers干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用SPServices从特定组获取SharePoint用户详细信息 - How to get SharePoint user details from a particular group using SPServices 使用Powershell Invoke-WebRequest从SharePoint列表中的人员或组列获取多个用户详细信息的问题 - Issues getting multiple user details from a person or group column in a SharePoint list with Powershell Invoke-WebRequest 获取当前登录用户的Sharepoint用户详细信息? (SOAP API) - Get Sharepoint user details for currently logged in user? (SOAP API) Powershell从Sharepoint中的特定组中删除用户 - Powershell remove user from specific group in sharepoint 在Sharepoint C#WebPart中获取登录的用户详细信息 - Get logged in user details in sharepoint c# webpart 如何从 powershell 获得 Sharepoint 应用程序权限 - How to get Sharepoint app permission from powershell 使用PowerShell检索SharePoint中已部署解决方案的详细信息 - Retrieve Details of Deployed Solutions in SharePoint using PowerShell 从共享点组中获取用户并重定向 - Get user from sharepoint group and redirect 从共享点获取已删除的用户信息 - Get deleted user information from sharepoint 从列表中的SharePoint用户字段获取用户名 - Get username from SharePoint User field in List
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM