Link to home
Start Free TrialLog in
Avatar of Tim Ballin
Tim Ballin

asked on

Format Powershell Script as a Table

How can I alter this script so that the output will be in table format?

$arServer = Get-Content -Path "C:\ServerList.txt"

foreach ($strServer in $arServer){

    $colltems =Get-WmiObject -class Win32_OperatingSystem -computername $strServer

foreach($sProperty in $colltems)
{
   
   Write-Host "Computer name; " $strServer
   Write-Host $sProperty.Description
   Write-Host $sProperty.Caption
   Write-Host $sProperty.OSArchitecture
   Write-Host $sProperty.ServicePackMajorVersion

}
}

Open in new window

Avatar of Spencer Scherer
Spencer Scherer
Flag of United States of America image

What about this?  Is this what you were looking for?  Sorry if I misunderstood.

$arServer = Get-Content -Path "C:\ServerList.txt"

foreach ($strServer in $arServer){

    $colltems =Get-WmiObject -class Win32_OperatingSystem -computername $strServer

foreach($sProperty in $colltems)
{
   
   Get-WmiObject -class Win32_OperatingSystem -computername $sProperty| format-table

}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tim Ballin
Tim Ballin

ASKER

Seems like you're on the right track, but here's what I get when I try to run that:

Get-WmiObject : Invalid parameter 
At line:10 char:4
+    Get-WmiObject -class Win32_OperatingSystem -computername $sProperty| format-t ...
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 
Get-WmiObject : Invalid parameter 
At line:10 char:4
+    Get-WmiObject -class Win32_OperatingSystem -computername $sProperty| format-t ...
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 
Get-WmiObject : Invalid parameter 
At line:10 char:4
+    Get-WmiObject -class Win32_OperatingSystem -computername $sProperty| format-t ...
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Open in new window

Worked perfect!