0

I need to create a solution in powershell that iterates through all my user profiles, finds the ones that have empty work email fields, and populates that field with whatever is in the name field (which also happens to be the email address). I would have to type a novel to explain how I got to this issue but could someone help me out with the powershell please. I have been trying for a while now with no luck.

Thanks in advance!

  • How am I going to get the correct answer on my original question if you keep deleting my post letting the provider of the previous answer know its not working? Thanks for this post. It almost works but I am getting an error: Invalid String Value: Input must match string data type $profile[$empEmailAttr].Value = $profile[$empNameAttr].Value Any ideas how I can change this line to fix? I tried switching to the .add method I found on another post but same error. shareeditflag deleted by Mohamed El-Qassas MVP♦ 11 hours ago Why was your post deleted? See the help center. – Trevor Fielder Sep 26 '18 at 14:20
0

If you know which property names you want to check you can update a profile this way. AccountName attribute includes the domain like domain\\username. You may also try UserName.

$mysiteUrl = "https://mysite"
$empEmailAttr = "WorkEmail"
$empNameAttr = "AccountName"

$site = get-spsite $mysiteUrl
$context = Get-SPServiceContext $site
$profileMgr = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

$profiles = $profileMgr.GetEnumerator()

foreach ($profile in $profiles)
{   

    if([string]::IsNullOrEmpty($profile[$empEmailAttr].Value))
    {
        $profile[$empEmailAttr].Value = $profile[$empNameAttr].Value
        $profile.Commit()
    }


}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.