-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-AdServers.ps1
More file actions
48 lines (44 loc) · 1.43 KB
/
Get-AdServers.ps1
File metadata and controls
48 lines (44 loc) · 1.43 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
<#
.Synopsis
Gets all windows servers from Active Directory
.DESCRIPTION
Generates a List of AD computers whos operating system contains *Windows Server*
.EXAMPLE
Get-AdServers
.EXAMPLE
Get-AdServers -Properties *
.ROLE
JakesSysadminFunctions
.FUNCTIONALITY
Get all servers
#>
Function Get-AdServers{
#Requires -Modules ActiveDirectory
[CmdletBinding()] #Enable all the default paramters, including -Verbose
[Alias()]
Param(
[string[]]$Properties,
[string]$SearchBase = (Get-ADDomain).DistinguishedName
)
Begin{
Write-Verbose -Message "Starting $($MyInvocation.InvocationName) with $($PsCmdlet.ParameterSetName) parameterset..."
Write-Verbose -Message "Parameters are $($PSBoundParameters | Select-Object -Property *)"
}
Process{
try{
Write-Verbose -Message "Contacting AD"
if($Properties){
Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server*'} -SearchBase $SearchBase -Properties $Properties -ErrorAction Stop
}
else{
Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server*'} -SearchBase $SearchBase -ErrorAction Stop
}
}
catch{
Write-Error -Message "$_ went wrong"
}
}
End{
Write-Verbose -Message "Ending $($MyInvocation.InvocationName)..."
}
}