SCCM Container Query

I was asked to help write a script to query all machines that do not have the SCCM agent and produce their email address in a CSV file.

Import-Module 'D:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1' -Verbose

set-location "SITEID:"

$Members = Get-CMDevice -CollectionName "Inactive AD computers with SCCM 2012 Client"



$Members | foreach-object {




  If($Username -ne 'Administrator'){



            $email = (Get-ADUser $Username -properties mail).mail

            New-Object -TypeName PSCustomObject -Property @{   

                Username = $Username   

                Computername = $Computername    

                Email = $email} | Export-Csv -Path "Machines.csv" -NoTypeInformation -Append


            #who cares


        #write-host $name


   }#end if

}#end for each

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.