My boss asked me to get a report for all the computers on our domain with all the monitor information. I found this code that I like how the output is laid out. I would like to run this through a csv file with all of our computers. I have been trying to figure this out for a few days now with no luck. I just start learning PowerShell and this is over my head. I am hoping someone can help me with this.
Function Get-MonitorInfo
{
[CmdletBinding()]
Param
(
[Parameter(Position=0,ValueFromPipeLine=$true,ValueFromPipeLineByPropertyName=$true)]
[alias("CN","MachineName","Name","Computer")]
[string[]]$ComputerName = $ENV:ComputerName
)
# get the computername
Begin { $pipelineInput = -not $PSBoundParameters.ContainsKey('$ComputerName') }
Process
{
# get the monitor info into an array
Function DoWork([string]$ComputerName)
{
$ActiveMonitors = Get-WmiObject -Namespace root\wmi `
-Class wmiMonitorID -ComputerName $ComputerName
$monitorInfo = @()
# Get the host serial number
$ComputerSerialNumber = ((gwmi win32_SystemEnclosure).serialnumber)
foreach ($monitor in $ActiveMonitors)
{
$mon = $null
# Convert the objects to char type and $monitor object
$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
ComputerSerialNumber = $ComputerSerialNumber
WeekOfManufacture = $monitor.WeekOfManufacture
YearOfManufacture = $monitor.YearOfManufacture}
# Capturing the information into the arrary
$monitorInfo += $mon
}
# Write out the info
$monitorInfo
}
# if pipeline is true, continue.
if ($pipelineInput)
{ DoWork($ComputerName) }
else
{
foreach ($item in $ComputerName)
{
DoWork($item)
}
}
}
}
# Call the function and output the data to the screen,
Get-MonitorInfo | Format-Table -AutoSize