Showing posts with label User Profiles. Show all posts
Showing posts with label User Profiles. Show all posts

Sunday, July 29, 2012

Update created by column using powershell

Was busy in implementing a test site - my BA asked whether we can show the CEO's name instead of her name in the created by column of all items in a list.

$SPSite = New-Object Microsoft.SharePoint.SPSite("<site collection url>")
$SPWeb = $SPSite.AllWebs["<site name>"] 
$SPList = $SPWeb.Lists["<List Name>"] 
$SPListItemCollection = $SPList.Items 
$targetUser =$SPWeb.EnsureUser(“<user Windows ID>”)
foreach ($ListItem in $SPListItemCollection) 
    {   
        $ListItem["Author"] = $targetUser 
$ListItem.ModerationInformation.Status = "Approved"
        $ListItem.Update() 
    }
$SPWeb.Update()


Worked like a gem .... BA happy, CEO tooo :)

Tuesday, July 24, 2012

Query that retrieve User Profile properties of a specific SharePoint 2010 user

Have you ever thought of a query that retrieve User Profile properties of a specific SharePoint 2010 user?


I have been searching for this guy for long ... today I found it.



SELECT  userprof.NTName,  proplist.PropertyName,  usrprofval.PropertyVal 
 FROM [<<ProfileDB>>].[dbo].[UserProfile_Full] userprof WITH(NOLOCK)
 JOIN  [<<ProfileDB>>].[dbo].[userProfileValue] usrprofval 
     ON  usrprofval.RecordID =  userprof.RecordID
 JOIN  [<<ProfileDB>>].[dbo].[PropertyList]     proplist  
     ON  proplist.PropertyID =  usrprofval.PropertyID 
WHERE  userprof .NTName = '<<windowsID>>'


Note: Reading from the SharePoint databases programmatically, or manually, can cause unexpected locking within Microsoft SQL Server which can adversely affect performance.

Monday, February 27, 2012

Powershell alternative of stsadm -o migrateuser

Powershell alternative of stsadm -o migrateuser -oldlogin domain\oldid  -newlogin domain\newid  -ignoresidhistory

I found the following with the help of MSDN techies

Move-SPUser [-Identity] <SPUserPipeBind> -NewAlias <String> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-IgnoreSID <SwitchParameter>] [-WhatIf [<SwitchParameter>]]

Sunday, February 26, 2012

Change DisplayName after Windows ID change

In my clients  SharePoint 2010 my sites application, we were facing a strange issue. Our MySite app is integrated with enterprise AD and importing most of the properties from it. Few the users first name / last name changed recently which made changes in their AD Ids. The changes flown to user profile during next sync operation. We also executed the following MigrateUser command updates the user profile store for this user
stsadm -o migrateuser -oldlogin domain\oldid  -newlogin domain\newid  -ignoresidhistory
This resolved all the issues except the "Displayname at the top navigation still shows old name"....
Hours .... Days... tried all sorts of combinations .... At last I found the right combination
  • Process the name changes by issuing user migration (stsadm -o migrateuser)
  • Sets the ignore is active flag and deletes all profile sync log info (stsadm -o sync -ignoreisactive 1)
  • Changes the profile full sync timer job schedule temporarily  (stsadm -o sync -deleteolddatabases 0)
  • Executes profile full sync timer job

WOW Im excited :)

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