Pages

Thursday 6 March 2014

Update User Profile using PowerShell


So, requirment goes here...

I was suppose to do change in user profile , for some employees who left the company.
so if you have a huge list of userprofile to update and doing it manually is a tedious task to do.
Just automate it..  :) 

Script refers a csv file, which contains domain and user details 
Snapshot:



 

 

 

Here is the script to update user profile


cls
Add-PSSnapIn "Microsoft.SharePoint.Powershell"

$mySiteUrl = "http://mysite.test.env.local"
$findProperty = "myproperty"  #property name here
$termName = "termname"  #term name here
$mySiteHostSite = Get-SPSite $mySiteUrl
$mySiteHostWeb = $mySiteHostSite.OpenWeb()
$context = Get-SPServiceContext $mySiteHostSite

# Obtain Profiles from the Profile Manager
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager ($context)

$create = Import-Csv -path C:\PowershellScript\UpdateBAGF.csv
ForEach($row in $create) {
    $userProfile = $upm.GetUserProfile($row.Domain + '\' + $row.LoginName)
    $t = $userProfile[$findProperty]
    $t.clear()
    $t.add($termName)
    $userProfile.Commit()
}

No comments:

Post a Comment