[英]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.