Author Posts

May 15, 2017 at 10:20 pm

How would I export this one-liner?

foreach ($domain in (Get-ADForest).domains) { 
  Get-ADDomainController -filter * -server $domain | 
  sort hostname  |
  foreach { 
    Get-CimInstance -ClassName Win32_ComputerSystem -ComputerName $psitem.Hostname |
    select @{name="DomainController";Expression={$_.PSComputerName}}, Manufacturer, Model,@{Name="TotalPhysicalMemory(GB)";Expression={ "{0:N0}" -f  ($_.TotalPhysicalMemory / 1Gb) }}
    }
}

May 16, 2017 at 1:01 pm

You want the morally correct way or the quick and dirty way?

May 18, 2017 at 12:38 am

$domain = (Get-ADForest).domains
$host = foreach ($d in $domain){(Get-ADDomainController -Server $d).hostname}

Get-CimInstance -ClassName Win32_ComputerSystem -ComputerName $host |
    Select-Object @{name="DomainController";Expression={$_.PSComputerName}},
    Manufacturer,Model,@{Name="TotalPhysicalMemory(GB)";
    Expression={"{0:N0}" -f  ($_.TotalPhysicalMemory / 1Gb)}} |
    Export-Csv \\path\to\export.csv -NoTypeInformation

May 18, 2017 at 10:58 pm

lol morally correct Don

May 18, 2017 at 10:59 pm

Thanks random

May 25, 2017 at 12:16 am

RCL,

Apparently, this script only outputs (1) DC per domain. I'd like output for all DC's in each domain.

May 25, 2017 at 6:10 am

[...]
$hosts = foreach ($d in $domain){(Get-ADDomainController -Server $d -Filter *).hostname}
[...]