-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathGet-DisabledUser.ps1
43 lines (35 loc) · 1.12 KB
/
Get-DisabledUser.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
#Requires –Version 3
function Get-DisabledUser {
param (
[Parameter(Mandatory = $true)]
[string]$UsersFilePath,
[Parameter(Mandatory = $false)]
[ValidateSet('Email', 'FullName', 'UserID')]
[string]$ListType = 'Email'
)
begin {
Import-Module ActiveDirectory
$Users = Get-Content -Path $UsersFilePath
$ADUsers = Get-ADUser -SearchBase 'OU=Users,DC=company,DC=LOCAL' -Filter *
$Results = @()
}
process {
foreach ($User in $Users) {
switch ($ListType) {
'Email' { $SearchProperty = 'UserPrincipalName' }
'FullName' { $SearchProperty = 'Name' }
'UserID' { $SearchProperty = 'SamAccountName' }
}
$FoundUser = $ADUsers | Where-Object { $_.$SearchProperty -eq $User }
$Results += New-Object -TypeName PSObject -Property @{
SearchProperty = $User
UserPrincipalName = $FoundUser.UserPrincipalName
Name = $FoundUser.Name
SamAccountName = $FoundUser.SamAccountName
Enabled = if ($FoundUser.Enabled) { $true } else { $false }
}
}
$Results | Sort-Object Enabled | Format-Table -AutoSize
}
}
Get-DisabledUser -UsersFilePath C:\TestUsers.txt -ListType Email