Thank you so much for your help. I got the -filter variable working based on your suggestions. Now I’ve run into one more problem. At the end when I out my $obj, it outputs fine on screen but when I check the csv file it only contains the last object that $obj held. How do I get it to write everything to the csv?
#Retrieves computer name and serial number and exports it to csv
function Get-ComputerInfo {
param(
$computername = $(Read-Host "Please enter the computer search parameters (ex: bhs72*)"),
$filename = $(Read-Host "Please enter the csv path and filename (ex: c:\test.csv)")
)
$comps = Get-ADComputer -filter { name -like $computername } | select -ExpandProperty name
foreach ($comp in $comps) {
$os = gwmi win32_operatingsystem -ComputerName $comp
$bios = gwmi win32_bios -ComputerName $comp
$properties = @{'Computername'=$comp;
'Serial Number'=$bios.serialnumber}
$obj = New-Object -TypeName psobject -Property $properties
Write-Output $obj
$obj | Export-Csv $filename -NoTypeInformation
}
}
Get-ComputerInfo