Im having an issue reading a .CSV file of computer names into a powershell script that i wrote. I want the script to read in the PC names and then export a .CSV file with all of the inventory fields populated. Here is the working code that i have so far:
function Get-CompInfo{
[cmdletBinding()]
param(
[string[]]$ComputerName,
[Switch]$errorLog,
[String]$logFile = 'C:\errorlog.txt'
)
Begin{
If($errorLog){
Write-Verbose 'Error logging turned on'
} Else {
write-verbose 'Error logging turned off'
}
Foreach($c in $ComputerName){
$os=Get-Wmiobject -ComputerName $c -Class win32_computersystem
$disk=Get-WmiObject -ComputerName $c -Class Win32_logicalDisk -Filter "DeviceID='C:'"
$vid=gwmi -ComputerName $c -class win32_VideoController
$bios=gwmi -ComputerName $c -Class win32_bios
$hdd=gwmi -ComputerName $c -class Win32_LogicalDisk
$mem=gwmi -ComputerName $c -class win32_physicalmemory |Measure-Object -Property capacity -Sum | % {[Math]::Round(($_.sum / 1GB),2)}
$prop=[ordered]@{
'computerName'=$c;
'Service tag'=$bios.serialnumber;
'PC Model'=$os.model;
'Hard Disk Size'=$disk.size / 1GB -as [int];
'Video Card'=$vid.description
'Memory (GB)'= $mem }
New-Object -TypeName psobject -Property $prop
Write-Output $obj
}
}
}
I run it using
Get-CompInfo -ComputerName receptionist