0

I was trying to get a user with EnsureUser to make sure that if the user doesn't exists on the site collection, it is added right away.

 Write-Host  "LoginName" $usernameau #this prints mydomain/username

         try {
           $userAuthor =  $spwebout.EnsureUser($usernameau) # getUserOut($usernameau)

        } catch   { 

        write-host $_.Exception 
        }

Unfortunately I get the following exception:

System.Management.Automation.MethodInvocationException: Exception calling "EnsureUser" with "1" argument(s): "The specified user  could not be found." ---> Microsoft.SharePoint.SPException: T
he specified user  could not be found.
   at Microsoft.SharePoint.SPWeb.EnsureUser(String logonName)
   at CallSite.Target(Closure , CallSite , Object , Object )
   --- End of inner exception stack trace ---
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

What could be the problem? I am sure the user exists on AD.

EDIT: I have to look better into it but I've found out is that the user that gives me the problem is not enabled in AD.

10
  • do you call it with or without domain name? ex: testdomain\user ? or do you maybe even have claims authentification?
    – Gwny
    Apr 22 '16 at 7:57
  • @Gwny I call it with the domain name
    – Gyonder
    Apr 22 '16 at 8:03
  • do you have claims?
    – Gwny
    Apr 22 '16 at 8:06
  • yes I have claims. I mean I have claims enabled. Or you mean something else?
    – Gyonder
    Apr 22 '16 at 8:06
  • 1
    have you tried ensuring it with de claims name?
    – Gwny
    Apr 22 '16 at 10:55
1

Found this solution in another thread...

$wApp = Get-SPWebApplication "http://nacho.sharepoint.taco"
$wApp.PeoplePickerSettings.SearchActiveDirectoryDomains.Clear() 

In my case, my people picker must have defaulted to the domain I was testing in, not the domain I was try to add users from. My Profile Store is configured to pull from two domain (Test and Prod).

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.