How to change user profile properties with PowerShell

I had an interesting little challenge crop up the other day that required me to need to change a custom user profile property inside of SharePoint’s 2010 User Profile Service Application. I have thousands of profiles and certainly didn’t want to get comfy with the mouse and keyboard all day, so I decided to whip up a little script to do the dirty work for me. Hopefully someone will find this useful as I couldn’t find it already put together.

 #Add-PSSnapin Microsoft.Sharepoint.Powershell
[reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint") | out-null
[reflection.assembly]::LoadWithPartialName("Microsoft.Office.Server") | out-null
[reflection.assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles") | out-null

$site = "http://sp2010dev"
$property = "Title"
$value = "TestValue123"

$spsite = Get-SPSite $site
$context = Get-SPServiceContext $site
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$enum = $upm.GetEnumerator()

while ($enum.MoveNext())
    [Microsoft.Office.Server.UserProfiles.UserProfile] $user = $enum.Current
    Write-Host "Working on profile for: " $user.DisplayName
    Write-Host "Old Value: " $($user[$property])
    $user[$property].value = $value
    Write-Host "New Value: " $($user[$property])