none
A user with the specified SID could not be found in the domain while adding users into UPSA using PowerShell RRS feed

  • Question

  • am trying to add a user profile through power shell programmatically , in my SP 2013 UPSA:

    here is my code :

     
    <#param (
        [string]$InputFile = $(throw '- Need parameter input file (e.g. "C:\users.xml")')
    )
    Trap [Exception]
    {
        Write-Host $_.Exception.Message -foregroundcolor Red break;
    }
    #>
     
    # SnapIn Load : SHAREPOINT
    Write-Host "Checking PowerShell Snapin"
    $snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
    if ($snapin -eq $null)
    {
        Write-Host -foregroundcolor Green "Loading SharePoint PowerShell Snapin"
        Add-PSSnapin "Microsoft.SharePoint.Powershell"
    }
     
    #Read Config File
    
    $InputFile = "E:\PoCSolutions\Users.xml"
    Write-Host "Reading configuration file $InputFile . . ."
    $xmlinput = [xml] (get-content $InputFile)
     
    # read site url
    $siteurl = $xmlinput.CONFIG.SITE
     
    # read user profile nodes
    $xmlProfiles = $xmlinput.CONFIG.PROFILES
    $profileNodes = $xmlProfiles.SelectNodes("PROFILE")
    $profileNodesCount = $profileNodes.Count
     
    Write-Host -ForegroundColor Cyan " Profiles will be created in $siteurl"
    Write-Host -ForegroundColor Cyan " Total of $profileNodesCount profiles are configured to be added"
     
    $mysite=new-object microsoft.sharepoint.spsite($siteurl)
    $servicecontext = get-spservicecontext($mysite)
    $userprofilemanager = new-object microsoft.office.server.userprofiles.userprofilemanager($servicecontext)
     
    $nodes = $xmlProfiles.SelectNodes("PROFILE")
    $eventsourcecount = $nodes.Count
    for($i = 0; $i -lt $profileNodesCount; $i++) {
        $profile = $profileNodes.Item($i)
        $login = $profile.LOGIN
        debug;
        $firstname = $profile.FIRSTNAME
        $lastname = $profile.LASTNAME
        $fullname = $profile.FULLNAME
        $email = $profile.EMAIL
        Write-Host -foregroundcolor Cyan " = = = = = = = = = = = = = = = = = = = = ="
        Write-Host -ForegroundColor Green " Creating user profile"
        Write-Host -ForegroundColor Green " Login      : $login"
        Write-Host -ForegroundColor Green " First Name : $firstname"
        Write-Host -ForegroundColor Green " Last Name  : $lastname"
        Write-Host -ForegroundColor Green " Full Name  : $fullname"
        Write-Host -ForegroundColor Green " Email      : $email"
        Write-Host -foregroundcolor Cyan " = = = = = = = = = = = = = = = = = = = = ="
        $newprofile = $userprofilemanager.createuserprofile($login)
        $newprofile.DisplayName = $fullname
        $newprofile["FirstName"].add($firstname)
        $newprofile["LastName"].add($lastname)
        $newprofile["WorkEmail"].add($email)
        $newprofile.commit()
    }
     
    <CONFIG>
      <SITE>http://srvr01:1234</SITE>
      <PROFILES>
        <PROFILE>
          <LOGIN>dom\\npd6</LOGIN>
          <FIRSTNAME>npd6</FIRSTNAME>
          <LASTNAME></LASTNAME>
          <FULLNAME>npd6</FULLNAME>
          <EMAIL>npd6@dom.com</EMAIL>
        </PROFILE>
        <!-- Profiles -->
        <PROFILE>
          <LOGIN>dom\\npd7</LOGIN>
          <FIRSTNAME>npd7</FIRSTNAME>
          <LASTNAME></LASTNAME>
          <FULLNAME>npd7</FULLNAME>
          <EMAIL>npd7@dom.com</EMAIL>
        </PROFILE>
      </PROFILES>
    </CONFIG>

    but am getting error like below:

     Exception calling "CreateUserProfile" with "1" argument(s): "A user with the specified SID could not be found in the domain.  Check the spelling of the account name 
    'dom\\npd7' and try again."
    At E:\PoCSolutions\Add_UserProfileUsers.ps1:58 char:5
    +     $newprofile = $userprofilemanager.createuserprofile($login)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : UserNotFoundException
     



     
    • Edited by SaMolPP Thursday, April 6, 2017 6:43 AM
    Thursday, April 6, 2017 6:39 AM

All replies