Last active
September 3, 2018 19:33
-
-
Save mczerniawski/8b248b77095d79177b63cfea2d8a3843 to your computer and use it in GitHub Desktop.
This file contains 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
$AdComputerFilter = 'DNSHostName','lastLogon','lastlogontimestamp','operatingSystem','operatingSystemVersion','whenChanged','whenCreated' | |
$SelectObjectFilter = @( | |
'DNSHostName', | |
@{name='lastLogon';e={[datetime]::FromFileTime($PSItem.'lastLogon') }}, | |
@{name='lastLogontimestamp';e={[datetime]::FromFileTime($PSItem.'lastLogontimestamp') }}, | |
'operatingSystem','operatingSystemVersion','whenCreated','whenChanged','DistinguishedName', | |
@{name='InUse';e={''}}, | |
@{name='CurrentAccessList';e={''}}, | |
@{name='Applications';e={''}}, | |
@{name='SystemUpdate';e={''}}, | |
@{name='PM';e={''}}, | |
@{name='TO';e={''}} | |
) | |
$domains = @( | |
@{ | |
Name = 'contoso.com' | |
Properties =@{ | |
Server = 'pdc1.contoso.com' | |
Credential = Get-Credential | |
SearchBase ='OU=Servers,OU=Computers,DC=contoso,DC=com' | |
Filter ='*' | |
} | |
}, | |
@{ | |
Name = 'farbikam.com' | |
Properties =@{ | |
Server = 'pdc1.fabrikam.com' | |
Credential = Get-Credential | |
SearchBase ='OU=Servers,OU=Computers,DC=fabrikam,DC=com' | |
Filter ='*' | |
} | |
} | |
) | |
$AllComputers = $domains | ForEach-Object { | |
$domainProperties = $PSItem.Properties | |
Get-ADComputer @domainProperties -Properties $AdComputerFilter | Select-Object $SelectObjectFilter | |
} | |
$FolderPath = 'D:\AdminTools\ServersInAD' | |
New-Item -ItemType directory -Path $FolderPath -force | |
$Allcomputers| Export-Csv -Path (Join-Path $FolderPath -ChildPath Allcomputers.csv) -Delimiter ',' -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment