Saturday, January 7, 2012

Quick way to dump UPS into a CSV file

Have you ever asked to get a CSV dump of user profiles from your SharePoint User Profile Service application....?


lets try this Powershell script 


$outfile = "c:\UserProfiles.csv"; 
$arProperties ="Accountname","FirstName","LastName","Workphone","Department","Title"; 
$mySiteUrl = "https://mysite.nilaa.com/"  
$site = new-object Microsoft.SharePoint.SPSite($mySiteUrl);  
$serviceContext = Get-SPServiceContext $site 
$upm = New-Object  Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext)

$ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)  
$AllProfiles = $ProfileManager.GetEnumerator()


$header = [string]::join("`t",$arProperties); 
$header | Out-File -FilePath $outfile -Encoding Unicode


$AllProfiles | ForEach-Object {  
  foreach($p in $arProperties){ $arProfileProps += $_.Item($p) + "`t"; } 
  $results = [string]::join($delim,$arProfileProps); 
  $CleanResults = $results.Replace("`n",''); 
  $CleanResults = $CleanResults.Replace(","," ");    
$CleanResults | Out-File -Append -FilePath $outfile -Encoding Unicode 
Remove-Variable -Name arProfileProps; 
    }

$site.Dispose()

No comments:

Post a Comment