开发者

Get user details from SharePoint with PowerShell

I'm using this PowerShell script to get site owners:

$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. How can I achieve that?


You have two choices I think. Access the SPUser properties or get information from active directory.

In the first case, are you not able to access the properties as you did for DisplayName? I mean if you have a SPUser object to get the email just use:

 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. FOr example you have not 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 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. To get information from a specific user you would use (I guess):

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

Cheers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜