Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$CSV = "C:\UserProfiles.csv"
$contextSiteUrl = "https://mysites.contoso.com/"
$serviceContext = Get-SPServiceContext -Site $contextSiteUrl
$UPMGR = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);
$AllUserProfile= $UPMGR.GetEnumerator()
$Properties = @(
"SID", "ADGuid", "AccountName","FirstName","LastName","PreferredName","CountryCode","PersonalUrl","WorkPhone","Office","Department","Title","Manager","AboutMe","UserName","SPS-Skills","SPS-School","SPS-Dotted-line",
"SPS-Peers","SPS-Responsibility","SPS-PastProjects","SPS-Interests","SPS-SipAddress","SPS-HireDate","SPS-Location","SPS-TimeZone","SPS-StatusNotes","Assistant","WorkEmail","SPS-ClaimID","SPS-ClaimProviderID","SPS-ClaimProviderType",
"CellPhone","Fax","HomePhone","PictureURL"
)
$Profilecollection = @()
foreach ($aProfile in $AllUserProfile) {
$UserProfile = "" | select $Properties
foreach ($field in $Properties) {
if($aProfile[$field].Property.IsMultivalued) {
try{
$UserProfile.$field = $aProfile[$field] -join "|" } catch {}
} else {
try{
$UserProfile.$field = $aProfile[$field].Value } catch {}
}
}
if($aProfile.PersonalSite -ne $null)
{
try{
$UserProfile.PersonalUrl = $aProfile.PersonalSite.Url
} catch {}
}
$Profilecollection += $UserProfile
}
$Profilecollection | Export-Csv $CSV -NoTypeInformation
Like this:
Like Loading...
Related
$Profilecollection | Export-Csv $outputFile -NoTypeInformation is to be corrected to
$Profilecollection | Export-Csv $CSV -NoTypeInformation else gives error of invalid or null path.
Thanks.
Sure. I will.