{"id":935,"date":"2018-12-28T06:41:39","date_gmt":"2018-12-28T06:41:39","guid":{"rendered":"https:\/\/www.tatvasoft.com.au\/blog\/?p=935"},"modified":"2022-03-17T07:51:28","modified_gmt":"2022-03-17T07:51:28","slug":"sharepoint-on-premise-create-user-and-assign-in-ad-sp-groups","status":"publish","type":"post","link":"https:\/\/www.tatvasoft.com.au\/blog\/sharepoint-on-premise-create-user-and-assign-in-ad-sp-groups\/","title":{"rendered":"Sharepoint On-premise \u2013 Create User and Assign in AD &#038; SP groups"},"content":{"rendered":"<p>In the real world, the HR department is responsible in any organization to appoint new employee. Once he\/she appoints any employee then he\/she requires to contact Network Administrator and SharePoint Administrator. A Network Administrator creates this user in the AD, assign him into OU (if require) and AD group, and a SharePoint Administrator assigns this user into appropriate SharePoint group to provide him access on the organization SharePoint site. Thus, a chronological sequence is required to follow and it is time-consuming.<\/p>\n<p>If HR department is having appropriate permission to access the organization SharePoint site then they can perform the tasks on behalf of Network and SharePoint Administrators through <a href=\"https:\/\/www.tatvasoft.com.au\/technologies\/sharepoint-development\/\">SharePoint<\/a> itself via a web-part, an application page or an event receiver. Thus, the HR department can get rid of the above chronological sequence.<\/p>\n<p>Before providing access to a new user in a SharePoint site, an organized user is required to perform certain steps as mentioned below:<\/p>\n<ol>\n<li>Create a user in Active Directory<\/li>\n<li>Add a user in Organizational Unit (if require)<\/li>\n<li>Add a user in Active Directory group<\/li>\n<li>Add a user in a SharePoint group<\/li>\n<\/ol>\n<p>Ideally, the Active Directory tasks (steps 1 to 3) are performed by a user who is having permission on Active Directory Domain Services. Step 4 can be performed by a user who is having access to manage users in SharePoint groups of a SharePoint site.<\/p>\n<p>Let\u2019s see how one can provide this functionality in SharePoint site.<\/p>\n<p><em><strong>Note<\/strong>: The yellow highlighted points in below code are configurable as per the user requirement. This information must be kept somewhere where one can easily manage them. E.g. web.config, app.config, SharePoint list etc.\u2003<\/em><\/p>\n<h2>Code Example<\/h2>\n<p>Let\u2019s create a console application in C# to create users in the AD and assign them into SharePoint Group. The developer can also add a piece of code in SharePoint web-part, an application page or an event receiver with required modification.<\/p>\n<p>First, get all the required user information from an end user and use them to create a user.<\/p>\n<div class=\"wp_syntax\" style=\"position: relative;\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"javascript\" style=\"font-family: monospace;\">Try\r\n       <span style=\"color: #009900;\">{<\/span>\r\n  <span style=\"color: #006600; font-style: italic;\">\/\/ fetch the user details from input  <\/span>\r\n                Console.<span style=\"color: #660066;\">Write<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Enter First name: \"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                <span style=\"color: #000066; font-weight: bold;\">var<\/span> firstName <span style=\"color: #339933;\">=<\/span> Console.<span style=\"color: #660066;\">ReadLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                Console.<span style=\"color: #660066;\">Write<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Enter Last name: \"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                <span style=\"color: #000066; font-weight: bold;\">var<\/span> lastName <span style=\"color: #339933;\">=<\/span> Console.<span style=\"color: #660066;\">ReadLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                Console.<span style=\"color: #660066;\">Write<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Enter Login name: \"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                <span style=\"color: #000066; font-weight: bold;\">var<\/span> loginName <span style=\"color: #339933;\">=<\/span> Console.<span style=\"color: #660066;\">ReadLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                Console.<span style=\"color: #660066;\">Write<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Enter Employee ID: \"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                <span style=\"color: #000066; font-weight: bold;\">var<\/span> employeeID <span style=\"color: #339933;\">=<\/span> Console.<span style=\"color: #660066;\">ReadLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                Console.<span style=\"color: #660066;\">Write<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Enter Email: \"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                <span style=\"color: #000066; font-weight: bold;\">var<\/span> email <span style=\"color: #339933;\">=<\/span> Console.<span style=\"color: #660066;\">ReadLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                Console.<span style=\"color: #660066;\">Write<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Enter Phone number: \"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                <span style=\"color: #000066; font-weight: bold;\">var<\/span> phoneNumber <span style=\"color: #339933;\">=<\/span> Console.<span style=\"color: #660066;\">ReadLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                Console.<span style=\"color: #660066;\">Write<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Enter Address: \"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                <span style=\"color: #000066; font-weight: bold;\">var<\/span> address <span style=\"color: #339933;\">=<\/span> Console.<span style=\"color: #660066;\">ReadLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n \r\n                AddUserInSharePoint<span style=\"color: #009900;\">(<\/span>firstName<span style=\"color: #339933;\">,<\/span> lastName<span style=\"color: #339933;\">,<\/span> loginName<span style=\"color: #339933;\">,<\/span> employeeID<span style=\"color: #339933;\">,<\/span> email<span style=\"color: #339933;\">,<\/span> phoneNumber<span style=\"color: #339933;\">,<\/span> address<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n            <span style=\"color: #009900;\">}<\/span>\r\n       <span style=\"color: #000066; font-weight: bold;\">catch<\/span> <span style=\"color: #009900;\">(<\/span>Exception ex<span style=\"color: #009900;\">)<\/span>\r\n       <span style=\"color: #009900;\">{<\/span>\r\n            Console.<span style=\"color: #660066;\">WriteLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Error: \"<\/span> <span style=\"color: #339933;\">+<\/span> ex.<span style=\"color: #660066;\">Message<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n       <span style=\"color: #009900;\">}<\/span>\r\n       Console.<span style=\"color: #660066;\">ReadLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"theCode\" style=\"display: none;\">Try { \/\/ fetch the user details from input Console.Write(&#8220;Enter First name: &#8220;); var firstName = Console.ReadLine(); Console.Write(&#8220;Enter Last name: &#8220;); var lastName = Console.ReadLine(); Console.Write(&#8220;Enter Login name: &#8220;); var loginName = Console.ReadLine(); Console.Write(&#8220;Enter Employee ID: &#8220;); var employeeID = Console.ReadLine(); Console.Write(&#8220;Enter Email: &#8220;); var email = Console.ReadLine(); Console.Write(&#8220;Enter Phone number: &#8220;); var phoneNumber = Console.ReadLine(); Console.Write(&#8220;Enter Address: &#8220;); var address = Console.ReadLine(); AddUserInSharePoint(firstName, lastName, loginName, employeeID, email, phoneNumber, address); } catch (Exception ex) { Console.WriteLine(&#8220;Error: &#8221; + ex.Message); } Console.ReadLine();<\/p>\n<\/div>\n<h3>Add User in SharePoint<\/h3>\n<div class=\"wp_syntax\" style=\"position: relative;\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"javascript\" style=\"font-family: monospace;\"> \r\npublic <span style=\"color: #000066; font-weight: bold;\">static<\/span> <span style=\"color: #000066; font-weight: bold;\">void<\/span> AddUserInSharePoint<span style=\"color: #009900;\">(<\/span>string firstName<span style=\"color: #339933;\">,<\/span> string lastName<span style=\"color: #339933;\">,<\/span> string userLogonName<span style=\"color: #339933;\">,<\/span>  string employeeID<span style=\"color: #339933;\">,<\/span> string emailAddress<span style=\"color: #339933;\">,<\/span> string telephone<span style=\"color: #339933;\">,<\/span> string address<span style=\"color: #009900;\">)<\/span>\r\n<span style=\"color: #009900;\">{<\/span>\r\n   <span style=\"color: #000066; font-weight: bold;\">try<\/span>\r\n   <span style=\"color: #009900;\">{<\/span>\r\n      bool status <span style=\"color: #339933;\">=<\/span> CreateUser<span style=\"color: #009900;\">(<\/span>firstName<span style=\"color: #339933;\">,<\/span> lastName<span style=\"color: #339933;\">,<\/span> loginName<span style=\"color: #339933;\">,<\/span> employeeID<span style=\"color: #339933;\">,<\/span> email<span style=\"color: #339933;\">,<\/span> phoneNumber<span style=\"color: #339933;\">,<\/span> address<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n \r\n      <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>status<span style=\"color: #009900;\">)<\/span>\r\n      <span style=\"color: #009900;\">{<\/span>\r\n            PrincipalContext AD <span style=\"color: #339933;\">=<\/span> <span style=\"color: #000066; font-weight: bold;\">new<\/span> PrincipalContext<span style=\"color: #009900;\">(<\/span>ContextType.<span style=\"color: #660066;\">Domain<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #3366cc;\">\"your     domain\"<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #3366cc;\">\"User Name\"<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #3366cc;\">\"Password\"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n            UserPrincipal u <span style=\"color: #339933;\">=<\/span> <span style=\"color: #000066; font-weight: bold;\">new<\/span> UserPrincipal<span style=\"color: #009900;\">(<\/span>AD<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n            <span style=\"color: #006600; font-style: italic;\">\/\/ search for user  <\/span>\r\n            PrincipalSearcher search <span style=\"color: #339933;\">=<\/span> <span style=\"color: #000066; font-weight: bold;\">new<\/span> PrincipalSearcher<span style=\"color: #009900;\">(<\/span>u<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n            UserPrincipal result <span style=\"color: #339933;\">=<\/span> <span style=\"color: #009900;\">(<\/span>UserPrincipal<span style=\"color: #009900;\">)<\/span>search.<span style=\"color: #660066;\">FindOne<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n            search.<span style=\"color: #660066;\">Dispose<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n            <span style=\"color: #006600; font-style: italic;\">\/\/Enter user to SharePoint group<\/span>\r\n            <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>result <span style=\"color: #339933;\">!=<\/span> <span style=\"color: #003366; font-weight: bold;\">null<\/span><span style=\"color: #009900;\">)<\/span>\r\n            <span style=\"color: #009900;\">{<\/span>\r\n                  AddUserToDirectoryGroup<span style=\"color: #009900;\">(<\/span>result.<span style=\"color: #660066;\">UserPrincipalName<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #3366cc;\">\"AD Group Name\"<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #3366cc;\">\"Your Domain\"<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #3366cc;\">\"DC=DC,DC=DC\"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                  AddUserToSharePointGroup<span style=\"color: #009900;\">(<\/span>result.<span style=\"color: #660066;\">SamAccountName<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #3366cc;\">\"SP Group Name\"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span> <span style=\"color: #006600; font-style: italic;\">\/\/ SamAccountName = User's AD login name<\/span>\r\n            <span style=\"color: #009900;\">}<\/span>\r\n       <span style=\"color: #009900;\">}<\/span>\r\n   <span style=\"color: #009900;\">}<\/span>\r\n   <span style=\"color: #000066; font-weight: bold;\">catch<\/span> <span style=\"color: #009900;\">(<\/span>DirectoryServicesCOMException ex<span style=\"color: #009900;\">)<\/span>\r\n   <span style=\"color: #009900;\">{<\/span>\r\n      Console.<span style=\"color: #660066;\">WriteLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Error: \"<\/span> <span style=\"color: #339933;\">+<\/span> ex.<span style=\"color: #660066;\">Message<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n   <span style=\"color: #009900;\">}<\/span>\r\n<span style=\"color: #009900;\">}<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"theCode\" style=\"display: none;\">public static void AddUserInSharePoint(string firstName, string lastName, string userLogonName, string employeeID, string emailAddress, string telephone, string address) { try { bool status = CreateUser(firstName, lastName, loginName, employeeID, email, phoneNumber, address); if (status) { PrincipalContext AD = new PrincipalContext(ContextType.Domain, &#8220;your domain&#8221;, &#8220;User Name&#8221;, &#8220;Password&#8221;); UserPrincipal u = new UserPrincipal(AD); \/\/ search for user PrincipalSearcher search = new PrincipalSearcher(u); UserPrincipal result = (UserPrincipal)search.FindOne(); search.Dispose(); \/\/Enter user to SharePoint group if (result != null) { AddUserToDirectoryGroup(result.UserPrincipalName, &#8220;AD Group Name&#8221;, &#8220;Your Domain&#8221;, &#8220;DC=DC,DC=DC&#8221;); AddUserToSharePointGroup(result.SamAccountName, &#8220;SP Group Name&#8221;); \/\/ SamAccountName = User&#8217;s AD login name } } } catch (DirectoryServicesCOMException ex) { Console.WriteLine(&#8220;Error: &#8221; + ex.Message); } }<\/p>\n<\/div>\n<h3>Create User<\/h3>\n<div class=\"wp_syntax\" style=\"position: relative;\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"javascript\" style=\"font-family: monospace;\">private <span style=\"color: #000066; font-weight: bold;\">static<\/span> bool CreateUser<span style=\"color: #009900;\">(<\/span>string firstName<span style=\"color: #339933;\">,<\/span> string lastName<span style=\"color: #339933;\">,<\/span> string userLogonName<span style=\"color: #339933;\">,<\/span>  string employeeID<span style=\"color: #339933;\">,<\/span> string emailAddress<span style=\"color: #339933;\">,<\/span> string telephone<span style=\"color: #339933;\">,<\/span> string address<span style=\"color: #009900;\">)<\/span>\r\n <span style=\"color: #009900;\">{<\/span>\r\n   <span style=\"color: #006600; font-style: italic;\">\/\/ Creating the PrincipalContext<\/span>\r\n   PrincipalContext principalContext <span style=\"color: #339933;\">=<\/span> <span style=\"color: #003366; font-weight: bold;\">null<\/span><span style=\"color: #339933;\">;<\/span>\r\n   <span style=\"color: #000066; font-weight: bold;\">try<\/span>\r\n   <span style=\"color: #009900;\">{<\/span>\r\n    principalContext <span style=\"color: #339933;\">=<\/span> <span style=\"color: #000066; font-weight: bold;\">new<\/span> PrincipalContext<span style=\"color: #009900;\">(<\/span>ContextType.<span style=\"color: #660066;\">Domain<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #3366cc;\">\"your domain\"<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #3366cc;\">\"DC=DC,DC=DC\"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n    <span style=\"color: #009900;\">}<\/span>\r\n    <span style=\"color: #000066; font-weight: bold;\">catch<\/span> <span style=\"color: #009900;\">(<\/span>Exception ex<span style=\"color: #009900;\">)<\/span>\r\n    <span style=\"color: #009900;\">{<\/span>\r\n         Console.<span style=\"color: #660066;\">WriteLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Error: \"<\/span> <span style=\"color: #339933;\">+<\/span> ex.<span style=\"color: #660066;\">Message<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n         <span style=\"color: #000066; font-weight: bold;\">throw<\/span> ex<span style=\"color: #339933;\">;<\/span>\r\n    <span style=\"color: #009900;\">}<\/span>\r\n \r\n    <span style=\"color: #006600; font-style: italic;\">\/\/ Check if user object already exists in the store<\/span>\r\n    UserPrincipal usr <span style=\"color: #339933;\">=<\/span> UserPrincipal.<span style=\"color: #660066;\">FindByIdentity<\/span><span style=\"color: #009900;\">(<\/span>principalContext<span style=\"color: #339933;\">,<\/span> userLogonName<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n    <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>usr <span style=\"color: #339933;\">!=<\/span> <span style=\"color: #003366; font-weight: bold;\">null<\/span><span style=\"color: #009900;\">)<\/span>\r\n    <span style=\"color: #009900;\">{<\/span>\r\n         <span style=\"color: #000066; font-weight: bold;\">return<\/span> <span style=\"color: #003366; font-weight: bold;\">false<\/span><span style=\"color: #339933;\">;<\/span>\r\n    <span style=\"color: #009900;\">}<\/span>\r\n \r\n    <span style=\"color: #006600; font-style: italic;\">\/\/ Create the new UserPrincipal object<\/span>\r\n    UserPrincipal userPrincipal <span style=\"color: #339933;\">=<\/span> <span style=\"color: #000066; font-weight: bold;\">new<\/span> UserPrincipal<span style=\"color: #009900;\">(<\/span>principalContext<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n \r\n    <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>lastName <span style=\"color: #339933;\">!=<\/span> <span style=\"color: #003366; font-weight: bold;\">null<\/span> <span style=\"color: #339933;\">&amp;&amp;<\/span> lastName.<span style=\"color: #660066;\">Length<\/span> <span style=\"color: #339933;\">&gt;<\/span> <span style=\"color: #cc0000;\">0<\/span><span style=\"color: #009900;\">)<\/span>\r\n    <span style=\"color: #009900;\">{<\/span> userPrincipal.<span style=\"color: #660066;\">Surname<\/span> <span style=\"color: #339933;\">=<\/span> lastName<span style=\"color: #339933;\">;<\/span> <span style=\"color: #009900;\">}<\/span>\r\n \r\n    <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>firstName <span style=\"color: #339933;\">!=<\/span> <span style=\"color: #003366; font-weight: bold;\">null<\/span> <span style=\"color: #339933;\">&amp;&amp;<\/span> firstName.<span style=\"color: #660066;\">Length<\/span> <span style=\"color: #339933;\">&gt;<\/span> <span style=\"color: #cc0000;\">0<\/span><span style=\"color: #009900;\">)<\/span>\r\n    <span style=\"color: #009900;\">{<\/span> userPrincipal.<span style=\"color: #660066;\">GivenName<\/span> <span style=\"color: #339933;\">=<\/span> firstName<span style=\"color: #339933;\">;<\/span> <span style=\"color: #009900;\">}<\/span>\r\n \r\n    <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>employeeID <span style=\"color: #339933;\">!=<\/span> <span style=\"color: #003366; font-weight: bold;\">null<\/span> <span style=\"color: #339933;\">&amp;&amp;<\/span> employeeID.<span style=\"color: #660066;\">Length<\/span> <span style=\"color: #339933;\">&gt;<\/span> <span style=\"color: #cc0000;\">0<\/span><span style=\"color: #009900;\">)<\/span>\r\n    <span style=\"color: #009900;\">{<\/span> userPrincipal.<span style=\"color: #660066;\">EmployeeId<\/span> <span style=\"color: #339933;\">=<\/span> employeeID<span style=\"color: #339933;\">;<\/span> <span style=\"color: #009900;\">}<\/span>\r\n \r\n    <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>emailAddress <span style=\"color: #339933;\">!=<\/span> <span style=\"color: #003366; font-weight: bold;\">null<\/span> <span style=\"color: #339933;\">&amp;&amp;<\/span> emailAddress.<span style=\"color: #660066;\">Length<\/span> <span style=\"color: #339933;\">&gt;<\/span> <span style=\"color: #cc0000;\">0<\/span><span style=\"color: #009900;\">)<\/span>\r\n    <span style=\"color: #009900;\">{<\/span> userPrincipal.<span style=\"color: #660066;\">EmailAddress<\/span> <span style=\"color: #339933;\">=<\/span> emailAddress<span style=\"color: #339933;\">;<\/span> <span style=\"color: #009900;\">}<\/span>\r\n \r\n    <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>telephone <span style=\"color: #339933;\">!=<\/span> <span style=\"color: #003366; font-weight: bold;\">null<\/span> <span style=\"color: #339933;\">&amp;&amp;<\/span> telephone.<span style=\"color: #660066;\">Length<\/span> <span style=\"color: #339933;\">&gt;<\/span> <span style=\"color: #cc0000;\">0<\/span><span style=\"color: #009900;\">)<\/span>\r\n    <span style=\"color: #009900;\">{<\/span> userPrincipal.<span style=\"color: #660066;\">VoiceTelephoneNumber<\/span> <span style=\"color: #339933;\">=<\/span> telephone<span style=\"color: #339933;\">;<\/span> <span style=\"color: #009900;\">}<\/span>\r\n \r\n    <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>userLogonName <span style=\"color: #339933;\">!=<\/span> <span style=\"color: #003366; font-weight: bold;\">null<\/span> <span style=\"color: #339933;\">&amp;&amp;<\/span> userLogonName.<span style=\"color: #660066;\">Length<\/span> <span style=\"color: #339933;\">&gt;<\/span> <span style=\"color: #cc0000;\">0<\/span><span style=\"color: #009900;\">)<\/span>\r\n    <span style=\"color: #009900;\">{<\/span> userPrincipal.<span style=\"color: #660066;\">SamAccountName<\/span> <span style=\"color: #339933;\">=<\/span> userLogonName<span style=\"color: #339933;\">;<\/span> <span style=\"color: #009900;\">}<\/span>\r\n \r\n    string pwdOfNewlyCreatedUser <span style=\"color: #339933;\">=<\/span> <span style=\"color: #3366cc;\">\"abcde@@12345!~\"<\/span><span style=\"color: #339933;\">;<\/span> <span style=\"color: #006600; font-style: italic;\">\/\/Random or auto-generated password can be assigned.<\/span>\r\n \r\n    userPrincipal.<span style=\"color: #660066;\">SetPassword<\/span><span style=\"color: #009900;\">(<\/span>pwdOfNewlyCreatedUser<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n \r\n    userPrincipal.<span style=\"color: #660066;\">Enabled<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #003366; font-weight: bold;\">true<\/span><span style=\"color: #339933;\">;<\/span>\r\n    userPrincipal.<span style=\"color: #660066;\">ExpirePasswordNow<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n \r\n    <span style=\"color: #000066; font-weight: bold;\">try<\/span>\r\n    <span style=\"color: #009900;\">{<\/span>\r\n       userPrincipal.<span style=\"color: #660066;\">Save<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n    <span style=\"color: #009900;\">}<\/span>\r\n    <span style=\"color: #000066; font-weight: bold;\">catch<\/span> <span style=\"color: #009900;\">(<\/span>Exception ex<span style=\"color: #009900;\">)<\/span>\r\n    <span style=\"color: #009900;\">{<\/span>\r\n       Console.<span style=\"color: #660066;\">WriteLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Error: \"<\/span> <span style=\"color: #339933;\">+<\/span> ex.<span style=\"color: #660066;\">Message<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n       <span style=\"color: #000066; font-weight: bold;\">return<\/span> <span style=\"color: #003366; font-weight: bold;\">false<\/span><span style=\"color: #339933;\">;<\/span>\r\n    <span style=\"color: #009900;\">}<\/span>\r\n \r\n    <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>userPrincipal.<span style=\"color: #660066;\">GetUnderlyingObjectType<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #339933;\">==<\/span> <span style=\"color: #000066; font-weight: bold;\">typeof<\/span><span style=\"color: #009900;\">(<\/span>DirectoryEntry<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span>\r\n    <span style=\"color: #009900;\">{<\/span>\r\n       DirectoryEntry entry <span style=\"color: #339933;\">=<\/span> <span style=\"color: #009900;\">(<\/span>DirectoryEntry<span style=\"color: #009900;\">)<\/span>userPrincipal.<span style=\"color: #660066;\">GetUnderlyingObject<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n       <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>address <span style=\"color: #339933;\">!=<\/span> <span style=\"color: #003366; font-weight: bold;\">null<\/span> <span style=\"color: #339933;\">&amp;&amp;<\/span> address.<span style=\"color: #660066;\">Length<\/span> <span style=\"color: #339933;\">&gt;<\/span> <span style=\"color: #cc0000;\">0<\/span><span style=\"color: #009900;\">)<\/span>\r\n       <span style=\"color: #009900;\">{<\/span> entry.<span style=\"color: #660066;\">Properties<\/span><span style=\"color: #009900;\">[<\/span><span style=\"color: #3366cc;\">\"streetAddress\"<\/span><span style=\"color: #009900;\">]<\/span>.<span style=\"color: #660066;\">Value<\/span> <span style=\"color: #339933;\">=<\/span> address<span style=\"color: #339933;\">;<\/span> <span style=\"color: #009900;\">}<\/span>\r\n \r\n<span style=\"color: #000066; font-weight: bold;\">try<\/span>\r\n       <span style=\"color: #009900;\">{<\/span>\r\n          entry.<span style=\"color: #660066;\">CommitChanges<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n       <span style=\"color: #009900;\">}<\/span>\r\n       <span style=\"color: #000066; font-weight: bold;\">catch<\/span> <span style=\"color: #009900;\">(<\/span>Exception ex<span style=\"color: #009900;\">)<\/span>\r\n       <span style=\"color: #009900;\">{<\/span>\r\n          Console.<span style=\"color: #660066;\">WriteLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Error: \"<\/span> <span style=\"color: #339933;\">+<\/span> ex.<span style=\"color: #660066;\">Message<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n          <span style=\"color: #000066; font-weight: bold;\">return<\/span> <span style=\"color: #003366; font-weight: bold;\">false<\/span><span style=\"color: #339933;\">;<\/span>\r\n       <span style=\"color: #009900;\">}<\/span>\r\n    <span style=\"color: #009900;\">}<\/span>\r\n \r\n    <span style=\"color: #000066; font-weight: bold;\">return<\/span> <span style=\"color: #003366; font-weight: bold;\">true<\/span><span style=\"color: #339933;\">;<\/span>\r\n   <span style=\"color: #009900;\">}<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"theCode\" style=\"display: none;\">private static bool CreateUser(string firstName, string lastName, string userLogonName, string employeeID, string emailAddress, string telephone, string address) { \/\/ Creating the PrincipalContext PrincipalContext principalContext = null; try { principalContext = new PrincipalContext(ContextType.Domain, &#8220;your domain&#8221;, &#8220;DC=DC,DC=DC&#8221;); } catch (Exception ex) { Console.WriteLine(&#8220;Error: &#8221; + ex.Message); throw ex; } \/\/ Check if user object already exists in the store UserPrincipal usr = UserPrincipal.FindByIdentity(principalContext, userLogonName); if (usr != null) { return false; } \/\/ Create the new UserPrincipal object UserPrincipal userPrincipal = new UserPrincipal(principalContext); if (lastName != null &amp;&amp; lastName.Length &gt; 0) { userPrincipal.Surname = lastName; } if (firstName != null &amp;&amp; firstName.Length &gt; 0) { userPrincipal.GivenName = firstName; } if (employeeID != null &amp;&amp; employeeID.Length &gt; 0) { userPrincipal.EmployeeId = employeeID; } if (emailAddress != null &amp;&amp; emailAddress.Length &gt; 0) { userPrincipal.EmailAddress = emailAddress; } if (telephone != null &amp;&amp; telephone.Length &gt; 0) { userPrincipal.VoiceTelephoneNumber = telephone; } if (userLogonName != null &amp;&amp; userLogonName.Length &gt; 0) { userPrincipal.SamAccountName = userLogonName; } string pwdOfNewlyCreatedUser = &#8220;abcde@@12345!~&#8221;; \/\/Random or auto-generated password can be assigned. userPrincipal.SetPassword(pwdOfNewlyCreatedUser); userPrincipal.Enabled = true; userPrincipal.ExpirePasswordNow(); try { userPrincipal.Save(); } catch (Exception ex) { Console.WriteLine(&#8220;Error: &#8221; + ex.Message); return false; } if (userPrincipal.GetUnderlyingObjectType() == typeof(DirectoryEntry)) { DirectoryEntry entry = (DirectoryEntry)userPrincipal.GetUnderlyingObject(); if (address != null &amp;&amp; address.Length &gt; 0) { entry.Properties[&#8220;streetAddress&#8221;].Value = address; } try { entry.CommitChanges(); } catch (Exception ex) { Console.WriteLine(&#8220;Error: &#8221; + ex.Message); return false; } } return true; }<\/p>\n<\/div>\n<h3>Add User to Directory Group<\/h3>\n<div class=\"wp_syntax\" style=\"position: relative;\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"javascript\" style=\"font-family: monospace;\"> \r\npublic <span style=\"color: #000066; font-weight: bold;\">static<\/span> <span style=\"color: #000066; font-weight: bold;\">void<\/span> AddUserToDirectoryGroup<span style=\"color: #009900;\">(<\/span>string userId<span style=\"color: #339933;\">,<\/span> string groupName<span style=\"color: #339933;\">,<\/span> string domain<span style=\"color: #339933;\">,<\/span> string domainController<span style=\"color: #009900;\">)<\/span>\r\n<span style=\"color: #009900;\">{<\/span>\r\n   <span style=\"color: #000066; font-weight: bold;\">try<\/span>\r\n   <span style=\"color: #009900;\">{<\/span>\r\n      using <span style=\"color: #009900;\">(<\/span>PrincipalContext pc <span style=\"color: #339933;\">=<\/span> <span style=\"color: #000066; font-weight: bold;\">new<\/span> PrincipalContext<span style=\"color: #009900;\">(<\/span>ContextType.<span style=\"color: #660066;\">Domain<\/span><span style=\"color: #339933;\">,<\/span> domain<span style=\"color: #339933;\">,<\/span> domainController<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span>\r\n      <span style=\"color: #009900;\">{<\/span>\r\n         GroupPrincipal group <span style=\"color: #339933;\">=<\/span> GroupPrincipal.<span style=\"color: #660066;\">FindByIdentity<\/span><span style=\"color: #009900;\">(<\/span>pc<span style=\"color: #339933;\">,<\/span> groupName<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n         group.<span style=\"color: #660066;\">Members<\/span>.<span style=\"color: #660066;\">Add<\/span><span style=\"color: #009900;\">(<\/span>pc<span style=\"color: #339933;\">,<\/span> IdentityType.<span style=\"color: #660066;\">UserPrincipalName<\/span><span style=\"color: #339933;\">,<\/span> userId<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n         group.<span style=\"color: #660066;\">Save<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n      <span style=\"color: #009900;\">}<\/span>\r\n   <span style=\"color: #009900;\">}<\/span>\r\n   <span style=\"color: #000066; font-weight: bold;\">catch<\/span> <span style=\"color: #009900;\">(<\/span>DirectoryServicesCOMException ex<span style=\"color: #009900;\">)<\/span>\r\n   <span style=\"color: #009900;\">{<\/span>\r\n      Console.<span style=\"color: #660066;\">WriteLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Error: \"<\/span> <span style=\"color: #339933;\">+<\/span> ex.<span style=\"color: #660066;\">Message<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n   <span style=\"color: #009900;\">}<\/span>\r\n<span style=\"color: #009900;\">}<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"theCode\" style=\"display: none;\">public static void AddUserToDirectoryGroup(string userId, string groupName, string domain, string domainController) { try { using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domain, domainController)) { GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, groupName); group.Members.Add(pc, IdentityType.UserPrincipalName, userId); group.Save(); } } catch (DirectoryServicesCOMException ex) { Console.WriteLine(&#8220;Error: &#8221; + ex.Message); } }<\/p>\n<\/div>\n<h3>Add User to SharePoint Group<\/h3>\n<div class=\"wp_syntax\" style=\"position: relative;\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"javascript\" style=\"font-family: monospace;\"> \r\nprivate <span style=\"color: #000066; font-weight: bold;\">static<\/span> <span style=\"color: #000066; font-weight: bold;\">void<\/span> AddUserToSharePointGroup<span style=\"color: #009900;\">(<\/span>string userLoginName<span style=\"color: #339933;\">,<\/span> string userGroupName<span style=\"color: #009900;\">)<\/span>\r\n<span style=\"color: #009900;\">{<\/span>\r\n    <span style=\"color: #006600; font-style: italic;\">\/\/Executes this method with Full Control rights even if the user does not otherwise have Full Control<\/span>\r\n    SPSecurity.<span style=\"color: #660066;\">RunWithElevatedPrivileges<\/span><span style=\"color: #009900;\">(<\/span>delegate\r\n    <span style=\"color: #009900;\">{<\/span>\r\n        using <span style=\"color: #009900;\">(<\/span>SPSite spSite <span style=\"color: #339933;\">=<\/span> <span style=\"color: #000066; font-weight: bold;\">new<\/span> SPSite<span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Your site url\"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span>\r\n        <span style=\"color: #009900;\">{<\/span>\r\n            using <span style=\"color: #009900;\">(<\/span>SPWeb spWeb <span style=\"color: #339933;\">=<\/span> spSite.<span style=\"color: #660066;\">OpenWeb<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span>\r\n            <span style=\"color: #009900;\">{<\/span>\r\n                <span style=\"color: #000066; font-weight: bold;\">try<\/span>\r\n                <span style=\"color: #009900;\">{<\/span>\r\n                    <span style=\"color: #006600; font-style: italic;\">\/\/Allow updating of some sharepoint lists, (here spUsers, spGroups etc...)<\/span>\r\n                    spWeb.<span style=\"color: #660066;\">AllowUnsafeUpdates<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #003366; font-weight: bold;\">true<\/span><span style=\"color: #339933;\">;<\/span>\r\n \r\n                    SPUser spUser <span style=\"color: #339933;\">=<\/span> spWeb.<span style=\"color: #660066;\">EnsureUser<\/span><span style=\"color: #009900;\">(<\/span>userLoginName<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n \r\n                    <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>spUser <span style=\"color: #339933;\">!=<\/span> <span style=\"color: #003366; font-weight: bold;\">null<\/span><span style=\"color: #009900;\">)<\/span>\r\n                    <span style=\"color: #009900;\">{<\/span>\r\n                        SPGroup spGroup <span style=\"color: #339933;\">=<\/span> spWeb.<span style=\"color: #660066;\">Groups<\/span><span style=\"color: #009900;\">[<\/span>userGroupName<span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">;<\/span>\r\n \r\n                        <span style=\"color: #000066; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>spGroup <span style=\"color: #339933;\">!=<\/span> <span style=\"color: #003366; font-weight: bold;\">null<\/span><span style=\"color: #009900;\">)<\/span>\r\n                        <span style=\"color: #009900;\">{<\/span>\r\n                            spGroup.<span style=\"color: #660066;\">AddUser<\/span><span style=\"color: #009900;\">(<\/span>spUser<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                        <span style=\"color: #009900;\">}<\/span>\r\n                    <span style=\"color: #009900;\">}<\/span>\r\n                <span style=\"color: #009900;\">}<\/span>\r\n                <span style=\"color: #000066; font-weight: bold;\">catch<\/span> <span style=\"color: #009900;\">(<\/span>Exception ex<span style=\"color: #009900;\">)<\/span>\r\n                <span style=\"color: #009900;\">{<\/span>\r\n                    Console.<span style=\"color: #660066;\">WriteLine<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #3366cc;\">\"Error: \"<\/span> <span style=\"color: #339933;\">+<\/span> ex.<span style=\"color: #660066;\">Message<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n                <span style=\"color: #009900;\">}<\/span>\r\n                <span style=\"color: #000066; font-weight: bold;\">finally<\/span>\r\n                <span style=\"color: #009900;\">{<\/span>\r\n                    spWeb.<span style=\"color: #660066;\">AllowUnsafeUpdates<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #003366; font-weight: bold;\">false<\/span><span style=\"color: #339933;\">;<\/span>\r\n                <span style=\"color: #009900;\">}<\/span>\r\n            <span style=\"color: #009900;\">}<\/span>\r\n        <span style=\"color: #009900;\">}<\/span>\r\n    <span style=\"color: #009900;\">}<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n<span style=\"color: #009900;\">}<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"theCode\" style=\"display: none;\">private static void AddUserToSharePointGroup(string userLoginName, string userGroupName) { \/\/Executes this method with Full Control rights even if the user does not otherwise have Full Control SPSecurity.RunWithElevatedPrivileges(delegate { using (SPSite spSite = new SPSite(&#8220;Your site url&#8221;)) { using (SPWeb spWeb = spSite.OpenWeb()) { try { \/\/Allow updating of some sharepoint lists, (here spUsers, spGroups etc&#8230;) spWeb.AllowUnsafeUpdates = true; SPUser spUser = spWeb.EnsureUser(userLoginName); if (spUser != null) { SPGroup spGroup = spWeb.Groups[userGroupName]; if (spGroup != null) { spGroup.AddUser(spUser); } } } catch (Exception ex) { Console.WriteLine(&#8220;Error: &#8221; + ex.Message); } finally { spWeb.AllowUnsafeUpdates = false; } } } }); }<\/p>\n<\/div>\n<h3>Output<\/h3>\n<p>On successful execution of the <strong>AddUserInSharePoint<\/strong> method, the user will be added to the Active directory. You can verify the same by logging into the Active Directory. Refer the below screenshots for same.<\/p>\n<p><img loading=\"lazy\" class=\"wp-image-1394 size-full alignnone\" style=\"max-width: 100%; height: auto;\" title=\"Active Directory\" src=\"https:\/\/www.tatvasoft.com.au\/blog\/wp-content\/uploads\/2018\/12\/Active-Directory.png\" sizes=\"(max-width: 377px) 100vw, 377px\" srcset=\"https:\/\/www.tatvasoft.com.au\/blog\/wp-content\/uploads\/2018\/12\/Active-Directory.png 377w, https:\/\/www.tatvasoft.com.au\/blog\/wp-content\/uploads\/2018\/12\/Active-Directory-300x45.png 300w\" alt=\"Active Directory\" width=\"377\" height=\"56\" \/><\/p>\n<p><img loading=\"lazy\" class=\"wp-image-1395 alignnone\" style=\"max-width: 100%; height: auto;\" title=\"Test User Properties\" src=\"https:\/\/www.tatvasoft.com.au\/blog\/wp-content\/uploads\/2018\/12\/Test-User-Properties.png\" sizes=\"(max-width: 411px) 100vw, 411px\" srcset=\"https:\/\/www.tatvasoft.com.au\/blog\/wp-content\/uploads\/2018\/12\/Test-User-Properties.png 419w, https:\/\/www.tatvasoft.com.au\/blog\/wp-content\/uploads\/2018\/12\/Test-User-Properties-231x300.png 231w\" alt=\"Test User Properties\" width=\"411\" height=\"535\" \/><\/p>\n<p>On completion of <strong>AddUserToSharePointGroup<\/strong> method, the user will be added to a SharePoint group as shown in the screenshot below.<\/p>\n<p><img loading=\"lazy\" class=\"wp-image-1396 alignnone\" style=\"max-width: 100%; height: auto;\" title=\"SharePoint group\" src=\"https:\/\/www.tatvasoft.com.au\/blog\/wp-content\/uploads\/2018\/12\/SharePoint-group.png\" sizes=\"(max-width: 517px) 100vw, 517px\" srcset=\"https:\/\/www.tatvasoft.com.au\/blog\/wp-content\/uploads\/2018\/12\/SharePoint-group.png 558w, https:\/\/www.tatvasoft.com.au\/blog\/wp-content\/uploads\/2018\/12\/SharePoint-group-300x110.png 300w\" alt=\"SharePoint group\" width=\"517\" height=\"190\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>A new user can be created and assigned into the respective AD and SharePoint groups by a user who is having appropriate permission on a SharePoint site. The various information related to the user which is provided at a creation time can be viewed in SharePoint if the User Profile Synchronization Service is configured. Various operations can be performed in AD and SharePoint related to a user management.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the real world, the HR department is responsible in any organization to appoint new employee. Once he\/she appoints any&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1206,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Sharepoint On-premise -Create User &amp; Assign in AD &amp; SP groups<\/title>\n<meta name=\"description\" content=\"A new user can be created and assigned into the respective AD and SharePoint groups by a user who is having appropriate permission on a SharePoint site.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.tatvasoft.com.au\/blog\/sharepoint-on-premise-create-user-and-assign-in-ad-sp-groups\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sharepoint On-premise -Create User &amp; Assign in AD &amp; SP groups\" \/>\n<meta property=\"og:description\" content=\"A new user can be created and assigned into the respective AD and SharePoint groups by a user who is having appropriate permission on a SharePoint site.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.tatvasoft.com.au\/blog\/sharepoint-on-premise-create-user-and-assign-in-ad-sp-groups\/\" \/>\n<meta property=\"og:site_name\" content=\"TatvaSoft AU Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-12-28T06:41:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-17T07:51:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.tatvasoft.com.au\/blog\/wp-content\/uploads\/2018\/12\/sharepoint-onpremise-create-user-in-ad-and-sp-groups-2.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"750\" \/>\n\t<meta property=\"og:image:height\" content=\"375\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"6 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.tatvasoft.com.au\/blog\/#website\",\"url\":\"https:\/\/www.tatvasoft.com.au\/blog\/\",\"name\":\"TatvaSoft AU Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.tatvasoft.com.au\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.tatvasoft.com.au\/blog\/sharepoint-on-premise-create-user-and-assign-in-ad-sp-groups\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.tatvasoft.com.au\/blog\/wp-content\/uploads\/2018\/12\/sharepoint-onpremise-create-user-in-ad-and-sp-groups-2.jpg\",\"width\":750,\"height\":375,\"caption\":\"Sharepoint On-premise\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tatvasoft.com.au\/blog\/sharepoint-on-premise-create-user-and-assign-in-ad-sp-groups\/#webpage\",\"url\":\"https:\/\/www.tatvasoft.com.au\/blog\/sharepoint-on-premise-create-user-and-assign-in-ad-sp-groups\/\",\"name\":\"Sharepoint On-premise -Create User & Assign in AD & SP groups\",\"isPartOf\":{\"@id\":\"https:\/\/www.tatvasoft.com.au\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.tatvasoft.com.au\/blog\/sharepoint-on-premise-create-user-and-assign-in-ad-sp-groups\/#primaryimage\"},\"datePublished\":\"2018-12-28T06:41:39+00:00\",\"dateModified\":\"2022-03-17T07:51:28+00:00\",\"author\":{\"@id\":\"https:\/\/www.tatvasoft.com.au\/blog\/#\/schema\/person\/99be98dec950f3b1cdc014df166dd95c\"},\"description\":\"A new user can be created and assigned into the respective AD and SharePoint groups by a user who is having appropriate permission on a SharePoint site.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.tatvasoft.com.au\/blog\/sharepoint-on-premise-create-user-and-assign-in-ad-sp-groups\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.tatvasoft.com.au\/blog\/#\/schema\/person\/99be98dec950f3b1cdc014df166dd95c\",\"name\":\"tatvasoftadmin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.tatvasoft.com.au\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1ef69a3ae4a620ca0f649d8228bece0b?s=96&d=mm&r=g\",\"caption\":\"tatvasoftadmin\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/www.tatvasoft.com.au\/blog\/wp-json\/wp\/v2\/posts\/935"}],"collection":[{"href":"https:\/\/www.tatvasoft.com.au\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tatvasoft.com.au\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tatvasoft.com.au\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tatvasoft.com.au\/blog\/wp-json\/wp\/v2\/comments?post=935"}],"version-history":[{"count":5,"href":"https:\/\/www.tatvasoft.com.au\/blog\/wp-json\/wp\/v2\/posts\/935\/revisions"}],"predecessor-version":[{"id":1939,"href":"https:\/\/www.tatvasoft.com.au\/blog\/wp-json\/wp\/v2\/posts\/935\/revisions\/1939"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tatvasoft.com.au\/blog\/wp-json\/wp\/v2\/media\/1206"}],"wp:attachment":[{"href":"https:\/\/www.tatvasoft.com.au\/blog\/wp-json\/wp\/v2\/media?parent=935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tatvasoft.com.au\/blog\/wp-json\/wp\/v2\/categories?post=935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tatvasoft.com.au\/blog\/wp-json\/wp\/v2\/tags?post=935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}