-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManaging Users.ps1
55 lines (44 loc) · 1.69 KB
/
Managing Users.ps1
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
#Creating Users
New-ADUser -Surname 'Smith' -GivenName 'Richard' -Name 'Richard Smith' `
-DisplayName 'Richard Smith' -SamAccountName 'smithr' -UserPrincipalName 'smithr@int.acme.com' `
-Title 'Programmer' -Department 'IT' -City 'Toronto' -State 'Ontario' -Country 'CA' -EmployeeID '0001' `
-AccountPassword (ConvertTo-SecureString -String "Test1234!" -AsPlainText -Force) -Enabled:$true `
-Path (Get-ADOrganizationalUnit -Filter {name -like "Toronto1"})
#Another way to create a user, most recommended way
$ADUser=@{
Surname='Smith'
GivenName='Richard'
Name='Richard Smith'
DisplayName='Richard Smith'
SamAccountName='smithr'
UserPrincipalName='smithr@int.acme.com'
Title='Programmer'
Department='IT'
City='Toronto'
State='Ontario'
Country='CA'
EmployeeID='0001'
AccountPassword=(ConvertTo-SecureString -String "Test1234!" -AsPlainText -Force)
Path=(Get-ADOrganizationalUnit -Filter {name -like "Toronto1"})
Enabled=$true
}
New-ADUser @ADUser
$GetADUser=Get-ADUser -Identity smithr -Properties *
#Changing a users information
$ADMod=@{
City='New York'
State='New York'
Country='US'
}
$GetADUser | Set-ADUser @ADMod
#Moving a user to another OU
$MoveAD=@{
TargetPath=(Get-ADOrganizationalUnit -Filter {name -like 'New York1'})
}
$GetADUser | Move-ADObject @MoveAD
#Resetting a Users Password
$GetADUser=Get-ADUser -Identity smithr -Properties *
$GetADUser | Set-ADAccountPassword -NewPassword (ConvertTo-SecureString -String "Password!1234" -AsPlainText -Force) -Reset
$GetADUser | Set-ADUser -ChangePasswordAtLogon:$true
#Removing a User
$GetADUser | Remove-ADUser -Confirm:$false