Add SharePoint 2013 users to site collection using PowerShell

In SharePoint many times you give users permission but you would not be able to access them when using with custom app or custom component you  build until user access the site once. This is because SharePoint maintains the list of all the users  under User Information List. This list is hidden list that you cannot access from the user interface. Even if you go to this list it will only show you the users but not allow you to add users to the list.

Following PowerShell will add users to list without them accessing the site. the following code only adds one user but you can get creative and read the users from CSV or XML and add them in the loop.

$site = Get-SPSite https://SiteCollectionURL/
$web = $site.OpenWeb()
$user = $web.EnsureUser(“DOMAIN\user”)
$web.AllUsers.Add($user.LoginName,$user.Email, $user.Name,“Added Using PowerShell”)