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()

Sunday, January 1, 2012

Content types ordering in a document set


One of the new capabilities of SharePoint 2010 is the "Document Set" feature. Document Set enables users to group multiple documents, that support a single project or task, together into a single entity. All documents in a Document Set share the metadata and the entire set can also be versioned.

There is a minor issue if  selecting multiple content types into a document set while configuring the document set settings, and chose the content types, --- SharePoint places them alphabetically. Crazzy rite...?

If we don't want the document content types to be available on a library level, only inside the document set we canyt do it On a library level. We can configure this after a document set is created in the library (through 'change new button order'), but how can this be done on the content type level? good question right...

I fixed it in a tricky way - I created a document set by adding one content type at a time and saving it.

As part of creating a document set of 3 content types (First, Second , Last) in the given order 

  1. I created a document set content type (MyTest) by adding content type First. Then saved doc set.
  2. I opened that doc library and added MyTest content type to it
  3. Created a test document set of type MyTest. Removed the test doc set
  4. Opened document set content type (MyTest)  and added next content type Second. Saved it
  5. Created a test document set of type MyTest. Removed the test doc set
  6. Opened document set content type (MyTest)  and added next content type Last. Saved it
This worked perfect