Getting data from SCCM via Get-WmiObject
If anyone can help me out I would certainly appreciate it. I'm new to powershell and I'm not understanding it very well.
Here is what I'm trying to do, I have a script that pull computername from a txt file and does a foreach to bring back the data for each computer. I guess my syntax is not correct and I've been looking everywhere for information on how to do this.
Here is my script below.
$list = import-csv -path '.\Computers.txt'
$objectCollection=@()
$list | %{
$wmi_computersystem = Get-WmiObject -Class win32_ComputerSystem -ComputerName $_.computername
$wmi_SCCM = Get-WmiObject -Class SMS_R_System -ComputerName HFDSCCM -Namespace "root\SMS\Site_HFD" -Filter $("Name = '$_.computername'")
$object = New-Object psobject
Add-Member -InputObject $object -MemberType NoteProperty -Name Name -Value $wmi_computersystem.Name
Add-Member -InputObject $object -MemberType NoteProperty -Name SCCM_HostName -Value $wmi_SCCM.Name
Add-Member -InputObject $object -MemberType NoteProperty -Name SCCM_OS -Value $wmi_SCCM.ADSiteName
$objectCollection += $object
$object
$objectCollection | export-csv -path '.\ComputerInfo.csv' -NoTypeInformation -Append
}