# Change code from single comp to multiple comp.

**URL:** <https://forums.powershell.org/t/change-code-from-single-comp-to-multiple-comp/15535>\
**Category:** PowerShell Help\
**Created:** [January 27, 2021, 9:11am UTC](https://forums.powershell.org/t/change-code-from-single-comp-to-multiple-comp/15535 "2021-01-27T09:11:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zimba7768](https://avatars.discourse-cdn.com/v4/letter/z/439d5e/32.png) [@zimba7768](https://forums.powershell.org/u/zimba7768)\
**Post date:** [January 27, 2021, 9:11am UTC](https://forums.powershell.org/t/change-code-from-single-comp-to-multiple-comp/15535/1 "2021-01-27T09:11:21Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![ralphmwr](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ralphmwr/32/1064_2.png) [@ralphmwr](https://forums.powershell.org/u/ralphmwr)\
**Post date:** [January 27, 2021, 9:47am UTC](https://forums.powershell.org/t/change-code-from-single-comp-to-multiple-comp/15535/2 "2021-01-27T09:47:47Z")

</div>

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
@'
    Computername
    svr1
    svr2
    client2
    client3
'@ | Set-Content -Path $example_csv_file.FullName

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

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![zimba7768](https://avatars.discourse-cdn.com/v4/letter/z/439d5e/32.png) [@zimba7768](https://forums.powershell.org/u/zimba7768)\
**Post date:** [January 27, 2021, 10:04am UTC](https://forums.powershell.org/t/change-code-from-single-comp-to-multiple-comp/15535/3 "2021-01-27T10:04:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ralphmwr](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ralphmwr/32/1064_2.png) [@ralphmwr](https://forums.powershell.org/u/ralphmwr)\
**Post date:** [January 28, 2021, 2:25am UTC](https://forums.powershell.org/t/change-code-from-single-comp-to-multiple-comp/15535/4 "2021-01-28T02:25:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:27pm UTC](https://forums.powershell.org/t/change-code-from-single-comp-to-multiple-comp/15535/5 "2024-05-16T20:27:58Z")

</div>


