I wanted to view all user profiles in SharePoint. However, SharePoint only allows to see 50 users. I wrote the following PowerShell script which exports all user profiles.
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
$siteurl = "http://mysite/"
$site = New-Object Microsoft.SharePoint.SPSite($siteurl)
$context = [Microsoft.Office.Server.ServerContext]::GetContext($site)
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$upm.Count;
$profiles = $upm.GetEnumerator()
foreach ($userobject in $Profiles )
{
$ln = $userobject.item("Lastname")
$fn = $userobject.item("Firstname")
$account = $userobject.item("AccountName")
$user = $userobject.item("PreferredName")
$office = $userobject.item("Office")
Write-output "$fn;$ln;$user;$account;$office"
}
$site.Dispose()
No comments:
Post a Comment