Created
January 22, 2020 18:31
-
-
Save JustinGrote/4ef0576c224a3761a5dece2316ca7de6 to your computer and use it in GitHub Desktop.
Find all Enabled Servers in Active Directory that have checked in within a certain timeframe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -module ActiveDirectory | |
function Get-ActiveADServers { | |
param( | |
[String]$SearchBase, | |
[String]$Server, | |
[PSCredential]$Credential, | |
[DateTime]$After = (get-date).AddMonths(-1) | |
) | |
$GetADComputerParams = @{ | |
Filter = { | |
enabled -eq $true -and | |
operatingsystem -like '*server*' -and | |
lastlogondate -gt $After | |
} | |
SearchBase = $SearchBase | |
Property = 'lastLogonDate', 'operatingsystem' | |
Credential = $Credential | |
} | |
('SearchBase','Server','Credential').foreach{ | |
$optionalValue = (Get-Variable $PSItem -ErrorAction SilentlyContinue -ValueOnly) | |
if ($optionalValue) {$GetADComputerParams.$PSItem = $OptionalValue} | |
} | |
Get-AdComputer @GetAdComputerParams | | |
Select lastlogondate, operatingsystem, dnshostname, distinguishedname | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment