-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateHelpDeskUsers.ps1
More file actions
68 lines (57 loc) · 1.91 KB
/
Copy pathCreateHelpDeskUsers.ps1
File metadata and controls
68 lines (57 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$InputFile,
[Parameter(Mandatory = $false)]
[string]
$OutputFile = "NewUsers.csv",
[Parameter(Mandatory = $false)]
[string]
$Server = "dcc-h-dc01.ad.cannabis.ca.gov",
[Parameter(Mandatory = $false)]
[pscredential]
$Credential = (Get-Credential -Message "DA")
)
BEGIN {
$OU = "OU=DCA,OU=Standard,OU=Accounts,OU=DCC,DC=ad,DC=cannabis,DC=ca,DC=gov"
function GetPassword() {
$characters = @('abcdefghijkmnpqrstuvwxyz', 'ABCEFGHJKLMNPQRSTUVWXYZ', '23456789', '!@#$%')
$Password = Get-Password -PasswordLength 15 -Count 1 -InputStrings $characters
return $Password
}
$CSV = Import-Csv $InputFile
}
PROCESS {
foreach ($User in $CSV) {
$SamAccountName = $User.SamAccountName
Try {
$ADUser = Get-ADUser $SamAccountName -Server $Server
}
Catch {
$ADUser = $null
}
if ($ADUser) {
Write-Host "User $SamAccountName already exists." -ForegroundColor Red
Continue
}
$Password = GetPassword
$Attributes = @{
Name = $User.Name
DisplayName = $User.DisplayName
UserPrincipalName = $User.UserPrincipalName
Path = $OU
SamAccountName = $SamAccountName
AccountPassword = $(ConvertTo-SecureString -AsPlainText "$Password" -Force)
Enabled = $true
GivenName = $User.GivenName
Surname = $User.SurName
}
New-ADUser @Attributes -Server $Server -Credential $Credential
$User | Add-Member -MemberType NoteProperty -Name Password -Value $Password
$User | Export-Csv -NoTypeInformation -Append -LiteralPath $OutputFile
Write-Host "Created AD User $SamAccountName." -ForegroundColor Green
}
}
END {
}