0

I have tried to create a script for extracting but the output is not quite I desired.

$Servers = Get-ADDomainController -Filter * | Select-Object Name

foreach($server in $servers)
{
$compsystem = gwmi -q "Select * from win32_computersystem" | Select Model

write-output $Server is $compsystem"
}

The output is something like :

@{Name=ServerName} is @{Model=Proliant DL360 G6}

The servername is different but the Model is the same so i think it's in a continous loop after the first servers.

Any ideeas ?

Thank you,

Cranta Ionut
  • 179
  • 3
  • 3
  • 12

1 Answers1

0

You are never using the variable $server, so all your output is from the local machine you are running the script on. To run the command on the actual servers you can use Invoke-Command:

$servers |Foreach-Object {
    $compsystem = Invoke-Command -ComputerName $_.name -ScriptBlock { gwmi -q "Select * from win32_computersystem" }
    Write-Host ("{0} is {1}" -f $_.Name,$compsystem.Model)
}
Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79