Solved

Create AD user from client and not server with powershell

Posted on 2016-08-04
4
30 Views
Last Modified: 2016-08-04
I have not tested yet, but would I be able to create AD users from a workstation and not directory from the domain controller desktop using powershell?  Here is the script I have. It looks to work well on the server. I have not tried it from a workstation yet. Just wanted to get some advice first.  Would I need to have RSAT tools installed to do this from the workstation?


import-module activedirectory
$Input = Read-Host -Prompt "Input the user name as 'LastName, FirstName'"
$EmployeeID = Read-Host -Prompt "EmployeeID"
$Description = Read-Host -Prompt "Description"
$Department = Read-Host -Prompt "Department"
If ($Input -notmatch '\A\s*(?<LastName>\w+)\s*,\s*(?<FirstName>\w+)\s*\Z') {
	"Invalid input '$($Input)'" | Write-Error
	Exit 1
}
$LastName = $Matches['LastName']
$FirstName = $Matches['FirstName']

$ADUser = [ordered]@{}
$ADUser['Name'] =					"$($FirstName[0])$($LastName)"
$ADUser['SamAccountName'] =			"$($FirstName[0])$($LastName)"
$ADUser['GivenName'] =				$FirstName
$ADUser['Surname'] =				$LastName
$ADUser['DisplayName'] =			"$($FirstName) $($LastName)"
$ADUser['UserPrincipalName'] =		"$($FirstName[0])$($LastName)@homelab.com"
$ADUser['Path'] =					'OU=Staff,DC=homelab,DC=com'
$ADUser['AccountPassword'] =		ConvertTo-SecureString -AsPlainText 'P@ssw0rd' -Force
$ADUser['ChangePasswordAtLogon'] =	$True
$ADUser['Department'] =				$Department
$ADUser['Description'] =			$Description
$ADUser['EmailAddress'] =			"$($FirstName[0])$($LastName)@homelab.com"
$ADUser['Office'] =				$employeeID
$ADUser['Enabled'] =				$True
$ADUser['HomeDirectory'] =			"\\127.0.0.1\Share\$($ADUser['SamAccountName'])"
$ADUser['HomeDrive'] =				'H:'

"Creating a new user with the following properties:"
$ADUser.GetEnumerator() | Format-Table
New-ADUser @ADUser
Add-ADGroupMember "googleapps" –Member $($ADUser['SamAccountName'])
Add-ADGroupMember "yard-staff" –Member $($ADUser['SamAccountName'])

New-Item -type directory -path "\\127.0.0.1\Share\$($ADUser['SamAccountName'])"
$Acl = Get-Acl "\\127.0.0.1\Share\$($ADUser['SamAccountName'])"
$Ar = New-Object system.security.accesscontrol.filesystemaccessrule("$($FirstName[0])$($LastName)","FullControl","Allow")
$Acl.SetAccessRule($Ar)
Set-Acl "\\127.0.0.1\Share\$($ADUser['SamAccountName'])" $Acl

Open in new window

0
Comment
Question by:Roccat
  • 2
  • 2
4 Comments
 
LVL 21

Accepted Solution

by:
Joseph Moody earned 500 total points
Comment Utility
Yes. With RSAT installed, you would have the powershell ActiveDirectory module as well.
0
 

Author Comment

by:Roccat
Comment Utility
Would I need to specify a server in the code or will it just work with the domain that the computer is joined to?
0
 
LVL 21

Expert Comment

by:Joseph Moody
Comment Utility
You don't have to specify a DC or domain.
0
 

Author Closing Comment

by:Roccat
Comment Utility
Thank you!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now