Get user details from SharePoint with PowerShell
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
alex
software architect sharepoint ibm websphere MQ ibm datapower Oracle weblogic server
Updated on August 26, 2022Comments
-
alex over 1 year
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?