$user = Get-SPuser -Web $web -Identity $UserID

Get-SPUser : You must specify a valid user object or user identity.
At line:11 char:31
+             $user = get-SPuser <<<<  -Web $web -Identity $UserID
    + CategoryInfo          : InvalidArgument: (Microsoft.Share....SPUserPipeBind:SPUserPipeBind) [Get-SPUser], PSArgumentException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetUser

$user = $web.EnsureUser($username)
Exception calling "EnsureUser" with "1" argument(s): "The specified user Krishna could not be found."

How can I verify User exists in a site or not?
How can I fetch users without any exceptions?
If user doesn't exists, add user in site and fetch user.


1 Answer 1


You have to ensure your user first to validate the user identity.

$web = Get-SPWeb -identity $siteCollUrl
foreach ($User in $Users) { 
    Set-SPUser -Identity $User -Web $siteCollUrl -Group $group  

Everything which you require is in the below link,


  • Links to blogs are volatile. Please include real answer here May 17, 2017 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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