Export Collection to csv

#Export objects from from a collection specify attributes after "select-object"

[String]$CollectionID = "1234" #replace with the CollectionID that you want to generate the report for

[String]$SiteCode = "%SiteCode%" #This is the site code for the SCCM

[String]$Outfile = "%Path%\ExportName.csv" #Location where you want to drop the file.

$delimiter = ','

Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1"

Set-Location "$SiteCode`:"

$Machines = Get-CMCollectionMember -CollectionId $CollectionID | Select-Object #Name,Status,DeviceOS,DeviceOSBuild,IsVirtualMachine,IsActive,LastActiveTime,IsDecommissioned,SerialNumber,MACAddress,CNLastOnlineTime,CoManaged

$Machines | ConvertTo-Csv -Delimiter $delimiter -NoTypeInformation | out-file $Outfile -encoding ascii