-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDonsMods.psm1
134 lines (103 loc) · 5.98 KB
/
DonsMods.psm1
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
function global:Reset-PasswordTime($UserName){
try{
Write-Host -ForegroundColor Yellow "Looking for username:" $UserName
Set-ADUser -Identity $UserName -ChangePasswordAtLogon $true
Write-Host -ForegroundColor Cyan "Change Password At Logon set to true..."
Set-ADUser -Identity $UserName -ChangePasswordAtLogon $false
Write-Host -ForegroundColor Cyan "Change Password At Logon set to false..."
$passwordSet = Get-ADUser -Identity $UserName -Properties PasswordLastSet
Write-Host "Password last set changed to:" $passwordSet.PasswordLastSet
}
catch{
Write-Host -BackgroundColor Black -ForegroundColor Red "!!!-WARNING-!!!"
Write-Host -BackgroundColor Black -ForegroundColor Red "Unable to find:" $UserName
Write-Host -BackgroundColor Black -ForegroundColor Red "Did you even type it correctly?"
}
}
function global:Get-UserStatus($EmployeeID,$Unlock,$UserName,$ResetPasswordTime,$LastLogon,$PasswordLastSet) {
Import-Module ActiveDirectory
if($UserName){
Write-Host "You entered:" -ForegroundColor Magenta $UserName
Write-Host -ForegroundColor Yellow "Looking up information that matches Username:"$UserName
$userAccount = Get-ADUser -LDAPFilter "(SamAccountName=$UserName)" -Properties SamAccountName,GivenName,Surname,EmployeeID,LockedOut,PasswordLastSet,PasswordExpired,LastLogonDate
foreach($user in $userAccount){
Write-Host -ForegroundColor Yellow "Found: " $user.SamAccountName
Write-Host -ForegroundColor Yellow "With EmployeeID of:" $user.EmployeeID
Write-Host "-------------------------------------------------------"
}
if($PasswordLastSet -eq "yes"){
Write-Host -ForegroundColor cyan "Password Last Set:" $userAccount.PasswordLastSet
Write-Host -ForegroundColor cyan "Is Password Expired?:" $userAccount.PasswordExpired
Write-Host "-------------------------------------------------------"
}
if($ResetPasswordTime -eq "yes"){
Reset-PasswordTime -UserName $UserName
Write-Host "-------------------------------------------------------"
}
if($LastLogon -eq "yes"){
Write-Host -ForegroundColor cyan "Last Logon Date:" $userAccount.LastLogonDate
Write-Host "-------------------------------------------------------"
}
if($Unlock -eq "yes"){
Write-Host $userAccount
Write-Host -ForegroundColor Yellow "Attempting unlock on: " $userAccount.GivenName $userAccount.Surname
$userAccount | Unlock-ADAccount
if($userAccount.LockedOut -eq $false) {
Write-Host -ForegroundColor Yellow $userAccount.SamAccountName "is unlocked"
}
Write-Host "-------------------------------------------------------"
continue
}
else{
foreach($user in $userAccount){
If($user.LockedOut -eq $false){$lockedStatus = "No"}
else {$lockedStatus = "Yes"}
Write-Host "-------------------------------------------------------"
Write-Host -ForegroundColor Green "Username: " $user.SamAccountName
Write-Host -ForegroundColor Green "Firstname: " $user.GivenName
Write-Host -ForegroundColor Green "Lastname: " $user.Surname
Write-Host -ForegroundColor Green "EmployeeID#: " $user.EmployeeID
Write-Host -ForegroundColor Green "Is the account locked out?:" $lockedStatus
continue
}
}
}
else{
Write-Host $EmployeeID
$userAccount = Get-ADUser -LDAPFilter "(EmployeeID=$EmployeeID)" -Properties SamAccountName,GivenName,Surname,EmployeeID,LockedOut
foreach($user in $userAccount){Write-Host -ForegroundColor Yellow "Found: " $user.SamAccountName}
If($Unlock -eq "yes"){
foreach($user in $userAccount){
Write-Host -ForegroundColor Yellow "Attempting unlock associate: " $user.GivenName $user.Surname
Write-Host -ForegroundColor Yellow "Username:"$user.SamAccountName
$userAccount | Unlock-ADAccount
if($userAccount.LockedOut -eq $false) {
Write-Host -ForegroundColor Green $user.SamAccountName "is unlocked"
}
}
}
else{
foreach($user in $userAccount){
If($user.LockedOut -eq $false){$lockedStatus = "No"}
else {$lockedStatus = "Yes"}
Write-Host "-------------------------------------------------------"
Write-Host -ForegroundColor Green "Username: " $user.SamAccountName
Write-Host -ForegroundColor Green "Firstname: " $user.GivenName
Write-Host -ForegroundColor Green "Lastname: " $user.Surname
Write-Host -ForegroundColor Green "EmployeeID#: " $user.EmployeeID
Write-Host -ForegroundColor Green "Is the account locked out?:" $lockedStatus
}
}
}
}
function global:Get-LAPSPassword($ComputerName){
Import-Module ActiveDirectory
Write-Host -ForegroundColor Yellow "Getting LAPS password for computer #:" $ComputerName
$computer = Get-ADComputer -LDAPFilter "(Name=$ComputerName)" -Properties Name,ms-Mcs-AdmPwd,Enabled
write-host -ForegroundColor Cyan "Computer Name:" $computer.Name
Write-host -ForegroundColor Cyan "Is it enabled?" $computer.Enabled
Write-host -ForegroundColor Green "LAPS Password is:" $computer.'ms-Mcs-AdmPwd'
}
Export-ModuleMember -Function Get-UserStatus
Export-ModuleMember -Function Get-LAPSPassword
Export-ModuleMember -Function Reset-PasswordTime