Export defined properties of all users profiles in -UPS- SharePoint.
# ----------------------------------------------
# Author: Romain Blanchard
# Date: 20.06.2012
# Description: Export defined properties of all users profiles in -UPS- SharePoint.
# ----------------------------------------------
# Initialize
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
cls
# Settings
$begindate = Get-date
$logdate = Get-date -format yyyy-M-d
$logfile = "D:\WebAnalyticsResources\DataQualityChecking\SPUsers_Properties_$logdate.csv"
$logfileexist = Test-path $logfile
if ($logfileexist -eq "True"){ remove-item -path $logfile -Confirm:$false }
$siteurl = "http://rbla-sp2010-002/my/"
$mySiteHostSite = Get-SPSite $siteurl
$mySiteHostWeb = $mySiteHostSite.OpenWeb()
$context = Get-SPServiceContext $mySiteHostSite
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$count = 0
# Initialize csv file
write-output "AccountName;FirstName;LastName;DisplayName;PictureURL;Phone;Title;JobTitle;Department;Manager;Ask me About;Email;Mobile;Fax;Company;Address;Zip;City;Country" | out-file -filepath $logfile -append
write-host ""
write-host "----------------------------------"
write-host ""
# Script
$AllProfiles = $profileManager.GetEnumerator()
$numberofprofiles = $profileManager.Count
foreach($profile in $AllProfiles)
{
$AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
$user = $profileManager.GetUserProfile($AccountName)
# User's properties
$firstname = $user["FirstName"].Value
$lastname = $user["LastName"].Value
$name = $user["PreferredName"].Value
$picture = $user["PictureURL"].Value
$workphone = $user["WorkPhone"].Value
$title = $user["Title"].Value
$jobtitle = $user["SPS-JobTitle"].Value
$departement = $user["Department"].Value
$manager = $user["Manager"].Value
$askmeabout = $user["SPS-Responsibility"].Value
$workemail = $user["WorkEmail"].Value
$mobilephone = $user["CellPhone"].Value
$fax = $user["Fax"].Value
$company = $user["Company"].Value
$streetaddress = $user["StreetAddress"].Value
$zipcode = $user["ZipCode"].Value
$city = $user["City"].Value
$country = $user["Country"].Value
write-output "$AccountName;$firstname;$lastname;$name;$picture;$workphone;$title;$jobtitle;$departement;$manager;$askmeabout;$workemail;$mobilephone;$fax;$company;$streetaddress;$zipcode;$city;$country" | out-file -filepath $logfile -append
$count++
$a = ($count / $numberofprofiles)
$b = "{0:P2}" -f $a
Write-Progress -activity "Exporting data to CSV..." -status "Progress: $b"
}
Write-Progress "done" "done" -completed
write-host "Done!" -ForegroundColor Green
write-host ""
write-host "----------------------------------"
$enddate = Get-date
$datediff = (($enddate - $begindate)).ToString()
$mySiteHostSite.Dispose()
write-host ""
write-host "$count users found in $datediff min." -ForegroundColor Green
write-host ""
write-host "----------------------------------"