Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Cannot use variable as a get-adcomputer filter parameter

$
0
0

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


Viewing all articles
Browse latest Browse all 13067

Trending Articles