-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-ADExistence.ps1
45 lines (44 loc) · 1.35 KB
/
Get-ADExistence.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
<#
.Synopsis
Checks if computer account exists for computer names provided
.DESCRIPTION
Checks if computer account exists for computer names provided
.EXAMPLE
Get-ADExistence $computers
.EXAMPLE
Get-ADExistence "computer1","computer2"
#>
function Get-ADExistence
{
[CmdletBinding()]
Param
(
# single or array of machine names
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Enter one or multiple computer names")]
[String[]]$Computers
)
Begin{}
Process {
foreach ($computer in $computers) {
try {
$comp = get-adcomputer $computer -ErrorAction stop
$properties = @{computername = $computer
Enabled = $comp.enabled
InAD = 'Yes'}
}
catch {
$properties = @{computername = $computer
Enabled = 'Fat Chance'
InAD = 'No'}
}
finally {
$obj = New-Object -TypeName psobject -Property $properties
Write-Output $obj
}
} #End foreach
} #End Process
End{}
} #End Function