<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>New-ADUser Example Archives - the Sysadmin Channel</title>
	<atom:link href="https://thesysadminchannel.com/tag/new-aduser-example/feed/" rel="self" type="application/rss+xml" />
	<link>https://thesysadminchannel.com/tag/new-aduser-example/</link>
	<description>Documenting My Life as a System Administrator</description>
	<lastBuildDate>Tue, 17 Apr 2018 20:15:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
<site xmlns="com-wordpress:feed-additions:1">144174110</site>	<item>
		<title>Script: How to Automate your AD User Accounts with Powershell</title>
		<link>https://thesysadminchannel.com/script-create-user-accounts-in-powershell/</link>
					<comments>https://thesysadminchannel.com/script-create-user-accounts-in-powershell/#respond</comments>
		
		<dc:creator><![CDATA[Paul Contreras]]></dc:creator>
		<pubDate>Mon, 02 Apr 2018 05:44:39 +0000</pubDate>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[AD user account script]]></category>
		<category><![CDATA[automate active directory with powershell]]></category>
		<category><![CDATA[New-ADUser Example]]></category>
		<category><![CDATA[powershell create user accounts]]></category>
		<category><![CDATA[powershell script for active directory]]></category>
		<guid isPermaLink="false">https://thesysadminchannel.com/?p=210</guid>

					<description><![CDATA[<p>Create User Accounts in Powershell Tired of the old point and click method of creating AD user accounts?  So was I until I learned how to Create User Accounts in Powershell.  I love it!!  With the simple click of a&#8230; <a href="https://thesysadminchannel.com/script-create-user-accounts-in-powershell/" class="more-link">Continue Reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="https://thesysadminchannel.com/script-create-user-accounts-in-powershell/">Script: How to Automate your AD User Accounts with Powershell</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1><strong>Create User Accounts in Powershell</strong></h1>
<p>Tired of the old point and click method of creating AD user accounts?  So was I until I learned how to <strong>Create User Accounts in Powershell.</strong>  I love it!!  With the simple click of a button I have the PS window prompt me for the username and any other relevant information and poof! two seconds later my account is created.</p>
<p>In this article I am going to share the exact script I use to create regular active directory user accounts. All with the power of automation.</p>
<p>Before we&#8217;re able to run any Powershell scripts,  you&#8217;re going to need to <a href="https://thesysadminchannel.com/set-execution-policy-in-powershell/" target="_blank" rel="noopener">set your execution policy</a>. Check out the link for the refresher on how to do that.</p>
<h1><strong>Script to Create AD User Accounts</strong></h1>
<p>Now lets get to the good stuff.  The script I use is only for automating the creation of active directory user accounts.  This is not used for mail enabled accounts, or accounts in <a href="https://thesysadminchannel.com/office365/" target="_blank" rel="noopener">Office 365.</a>  I&#8217;ll post a link to each with its own script at the end of the article.</p>
<pre class="brush: powershell; title: ; notranslate">
&lt;# 
.SYNOPSIS
Creates a user account in active directory with information entered in by the user.

.DESCRIPTION
This will create a user in Active Directory automatically with Powershell.

.NOTES
Name: AD-CreateUserNoMailbox.ps1
Version: 1.0
Author: The Sysadmin Channel
Date of last revision: 12/18/2016

.LINK
https://thesysadminchannel.com/script-create-user-accounts-in-powershell/ -
#&gt;


#Checking if the shell is running as administrator.
#Requires -RunAsAdministrator
#Requires -Module ActiveDirectory
$title = &quot;Create a User Account in Active Directory&quot;

$host.ui.RawUI.WindowTitle = $title

Import-Module ActiveDirectory -EA Stop

sleep 5
cls


Write-Host
Write-Host
#Getting variable for the First Name
$firstname = Read-Host &quot;Enter in the First Name&quot;
Write-Host
#Getting variable for the Last Name
$lastname = Read-Host &quot;Enter in the Last Name&quot;
Write-Host
#Setting Full Name (Display Name) to the users first and last name
$fullname = &quot;$firstname $lastname&quot;
#Write-Host
#Setting username to first initial of first name along with the last name.
$i = 1
$logonname = $firstname.substring(0,$i) + $lastname
#Setting the employee ID.  Remove the '#' if you want to use the variable
#$empID = Read-Host &quot;Enter in the Employee ID&quot;
#Setting the Path for the OU.
$OU = &quot;OU=Users,OU=Home,DC=ad,DC=thesysadminchannel,DC=com&quot;
#Setting the variable for the domain.
$domain = $env:userdnsdomain
#Setting the variable for the description.
$Description = Read-Host &quot;Enter in the User Description&quot;


cls
#Displaying Account information.
Write-Host &quot;=======================================&quot;
Write-Host 
Write-Host &quot;Firstname:      $firstname&quot;
Write-Host &quot;Lastname:       $lastname&quot;
Write-Host &quot;Display name:   $fullname&quot;
Write-Host &quot;Logon name:     $logonname&quot;
Write-Host &quot;OU:             $OU&quot;
Write-Host &quot;Domain:         $domain&quot;

#Checking to see if user account already exists.  If it does it
#will append the next letter of the first name to the username.
DO
{
If ($(Get-ADUser -Filter {SamAccountName -eq $logonname})) {
        Write-Host &quot;WARNING: Logon name&quot; $logonname.toUpper() &quot;already exists!!&quot; -ForegroundColor:Green
        $i++
        $logonname = $firstname.substring(0,$i) + $lastname
        Write-Host
        Write-Host
        Write-Host &quot;Changing Logon name to&quot; $logonname.toUpper() -ForegroundColor:Green 
        Write-Host
        $taken = $true
        sleep 10
    } else {
    $taken = $false
    }
} Until ($taken -eq $false)
$logonname = $logonname.toLower()

cls
#Displaying account information that is going to be used.
Write-Host &quot;=======================================&quot;
Write-Host 
Write-Host &quot;Firstname:      $firstname&quot;
Write-Host &quot;Lastname:       $lastname&quot;
Write-Host &quot;Display name:   $fullname&quot;
Write-Host &quot;Logon name:     $logonname&quot;
Write-Host &quot;OU:             $OU&quot;
Write-Host &quot;Domain:         $domain&quot;



#Setting minimum password length to 12 characters and adding password complexity.
$PasswordLength = 12

Do
{
Write-Host
    $isGood = 0
    $Password = Read-Host &quot;Enter in the Password&quot; -AsSecureString
    $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)
    $Complexity = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)

    if ($Complexity.Length -ge $PasswordLength) {
                Write-Host
            } else {
                Write-Host &quot;Password needs $PasswordLength or more Characters&quot; -ForegroundColor:Green
        }

    if ($Complexity -match &quot;[^a-zA-Z0-9]&quot;) {
                $isGood++
            } else {
                Write-Host &quot;Password does not contain Special Characters.&quot; -ForegroundColor:Green
        }

    if ($Complexity -match &quot;[0-9]&quot;) {
                $isGood++
            } else {
                Write-Host &quot;Password does not contain Numbers.&quot; -ForegroundColor:Green
        }

    if ($Complexity -cmatch &quot;[a-z]&quot;) {
                $isGood++
            } else {
                Write-Host &quot;Password does not contain Lowercase letters.&quot; -ForegroundColor:Green
        }

    if ($Complexity -cmatch &quot;[A-Z]&quot;) {
                $isGood++
            } else {
                Write-Host &quot;Password does not contain Uppercase letters.&quot; -ForegroundColor:Green
        }

} Until ($password.Length -ge $PasswordLength -and $isGood -ge 3)


Write-Host 
Read-Host &quot;Press Enter to Continue Creating the Account&quot;
Write-Host &quot;Creating Active Directory user account now&quot; -ForegroundColor:Green

#Creating user account with the information you inputted.
New-ADUser -Name $fullname -GivenName $firstname -Surname $lastname -DisplayName $fullname -SamAccountName $logonname -UserPrincipalName $logonname@$Domain -AccountPassword $password -Enabled $true -Path $OU -Description $Description -Confirm:$false

sleep 2


Write-Host

$ADProperties = Get-ADUser $logonname -Properties *

Sleep 3

cls

Write-Host &quot;========================================================&quot;
Write-Host &quot;The account was created with the following properties:&quot;
Write-Host 
Write-Host &quot;Firstname:      $firstname&quot;
Write-Host &quot;Lastname:       $lastname&quot;
Write-Host &quot;Display name:   $fullname&quot;
Write-Host &quot;Logon name:     $logonname&quot;
Write-Host &quot;OU:             $OU&quot;
Write-Host &quot;Domain:         $domain&quot;
Write-Host
Write-Host
</pre>
<p>&nbsp;</p>
<div id="attachment_252" style="width: 1034px" class="wp-caption aligncenter"><a href="https://thesysadminchannel.com/wp-content/uploads/2018/03/Create-User-Accounts-in-Powershell-Finish.png" target="_blank" rel="noopener"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-252" class="wp-image-252 size-medium" src="https://thesysadminchannel.com/wp-content/uploads/2018/03/Create-User-Accounts-in-Powershell-Finish-1024x566.png" alt="Create User Accounts in Powershell Finish" width="1024" height="566" srcset="https://thesysadminchannel.com/wp-content/uploads/2018/03/Create-User-Accounts-in-Powershell-Finish-1024x566.png 1024w, https://thesysadminchannel.com/wp-content/uploads/2018/03/Create-User-Accounts-in-Powershell-Finish-768x425.png 768w, https://thesysadminchannel.com/wp-content/uploads/2018/03/Create-User-Accounts-in-Powershell-Finish.png 1392w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><p id="caption-attachment-252" class="wp-caption-text">This is the result of the script that outputs all the information of the user account.</p></div>
<p>So there you have it,  the user account has been created with the click of a single button.  You can even scale this to create multiple accounts at once.</p>
<p>&nbsp;</p>
<h1>Watch as I Create User Accounts in Powershell</h1>
<p><iframe title="Create User Accounts With Powershell | Active Directory Automated User Creation" width="640" height="360" src="https://www.youtube.com/embed/osAkS5UJAPk?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://thesysadminchannel.com/script-create-user-accounts-in-powershell/">Script: How to Automate your AD User Accounts with Powershell</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thesysadminchannel.com/script-create-user-accounts-in-powershell/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">210</post-id>	</item>
	</channel>
</rss>
