0
$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.

2
0

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

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

Everything which you require is in the below link,

http://www.manasbhardwaj.net/add-users-sharepoint-group-using-powershell/

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

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.