Learn how to get a site user using a login name. This sample show two different ways to get the user and includes a tip for creating a login name using a back slash character.
Prerequisites
This example requires a SharePoint site user with the login name "Luerkens\Jeremy" to exist in your site. Modify line one of the Get User syntax to include an alternate login name.
Syntax
| Get User | Copy Code |
|---|---|
|
#set( $loginName = "LUERKENS${StringUtility.Backslash}jeremy" ) <div style="padding:10px"> Login Name: $loginName </div> ## Error thrown if user doens't exist #set( $user1 = $web.SiteUsers.get_item($loginName) ) <div style="padding:10px"> Login Name: $user1.LoginName<br /> Display Name: $user1.Name<br /> E-Mail: $user1.Email<br /> </div> ## No Error thrown if user doesn't exist #set( $user2 = $SPUtility.GetUserNoThrow($web, $loginName) ) #if($user2) <div style="padding:10px"> Login Name: $user2.LoginName<br /> Display Name: $user2.Name<br /> E-Mail: $user2.Email<br /> </div> #else <div style="padding:10px"> The user $loginName could not be found. </div> #end | |

The $web (Microsoft.SharePoint.SPWeb) object has two separate users list: $web.Users, $web.SiteUsers. The $web.SiteUsers list contains a lit of all users who have access to the Site Collection. The $web.Users list only contains accounts that have been given direct access to the current site. Accounts that have been granted access to the site via a group will not exist in the $web.Users list. To get accounts in a group use the users list found on the Microsoft.SharePoint.SPGroup object.
![]() |
The $web (Microsoft.SharePoint.SPWeb) object has two separate users list: $web.Users, $web.SiteUsers. The $web.SiteUsers list contains a lit of all users who have access to the Site Collection. The $web.Users list only contains accounts that have been given direct access to the current site. Accounts that have been granted access to the site via a group will not exist in the $web.Users list. To get accounts in a group use the users list found on the Microsoft.SharePoint.SPGroup object. |
Output
