Skip to content

Instantly share code, notes, and snippets.

@mczerniawski
Last active September 3, 2018 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mczerniawski/8b248b77095d79177b63cfea2d8a3843 to your computer and use it in GitHub Desktop.
Save mczerniawski/8b248b77095d79177b63cfea2d8a3843 to your computer and use it in GitHub Desktop.
$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