Change code from single comp to multiple comp.

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



[string[]]$ComputerName = $ENV:ComputerName
# get the computername
Begin { $pipelineInput = -not $PSBoundParameters.ContainsKey('$ComputerName') }
# 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

# if pipeline is true, continue.
if ($pipelineInput)
{ DoWork($ComputerName) }
foreach ($item in $ComputerName)

# Call the function and output the data to the screen,

Get-MonitorInfo | Format-Table -AutoSize

Looks to me like your function will take a computername argument. Have you tried that? If so then just iterate over your csv file containing computername. Example:

$example_csv_file = New-TemporaryFile
'@ | Set-Content -Path $example_csv_file.FullName

foreach ($computer in Import-Csv -Path $example_csv_file.FullName)
    Get-MonitorInfo -ComputerName $computer.Computername



Thank you for replying so quickly. I can try this. Where would this go in the code? Sorry for the dumb question. I really am just starting out in learning PowerShell.

After the function (Get-MonitorInfo) definition. Obviously replace my example computers with your csv.