Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Format Output from List to Table

$
0
0

Greetings,

With the help of google I was able to find a script that suite my needs.  I need to modify it but I never had to modify the output from a list into a table.

Anyways, the script works find and I adjusted for my needs.  However, when the script query's the information it pulls in a way that is not as useful.

We have various configurations for the monitors.  All the way from 2 to 4.

Here is a sample of how it comes out

 

ComputerNameUserFriendlyName
----------------------------
Computer1HP L2401x
Computer1DELL P2314H
Computer2HP L2401x

But I need this ( or Monitor 1, Monitor 2 etc for the headers)

ComputerName UserFriendlyName UserFriendlyName
------------ ---------------- ----------------
Computer1    HP L2401x        HP L2401x
Computer2    HP L2401x        HP DELL P2314H

Script

FunctionGet-MonitorInfo
{
[CmdletBinding()]
Param
(
[Parameter(
Position=0,
ValueFromPipeLine=$true,
ValueFromPipeLineByPropertyName=$true)]
[alias("CN","MachineName","Name","Computer")]
[string[]]$ComputerName=$ENV:ComputerName
)

Begin {
$pipelineInput=-not$PSBoundParameters.ContainsKey('ComputerName')
}

Process
{
Function DoWork([string]$ComputerName) {
$ActiveMonitors=Get-WmiObject-Namespace root\wmi -Class wmiMonitorID -ComputerName$ComputerName
$monitorInfo= @()

foreach ($monitorin$ActiveMonitors)
{
$mon=$null

$mon=New-Object PSObject -Property @{
ManufacturerName=($monitor.ManufacturerName | % {[char]$_}) -join''
ProductCodeID=($monitor.ProductCodeID | % {[char]$_}) -join''
SerialNumberID=($monitor.SerialNumberID | % {[char]$_}) -join''
UserFriendlyName=($monitor.UserFriendlyName | % {[char]$_}) -join''
ComputerName=$ComputerName
WeekOfManufacture=$monitor.WeekOfManufacture
YearOfManufacture=$monitor.YearOfManufacture}

$monitorInfo+=$mon
}
Write-Output$monitorInfo
}

if ($pipelineInput) {
DoWork($ComputerName)
} else {
foreach ($itemin$ComputerName) {
DoWork($item)
}
}
}
}

 

Here is what I run.  This is just for view but I actually export to CSV still looks the same

Get-MonitorInfo-ComputerNameCOMPUTER|Select-ObjectComputerName,|Format-List

What do I need to modify so that it will come out on a list with headers?

Thank you

 

 

 

 

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles