Have you ever needed to send an email to all of the primary / last logged on / currently logged on user for every computer in a collection? Here’s a nice little PowerShell script that can help you out with that. Feel free to submit updates, issues, and requests in GitHub.
The latest code can be obtained from GitHub. https://github.com/ChadSimmons/Scripts/blob/default/ConfigMgr/Document/Get-MECMDeviceCollectionPrimaryEmailAddresses.ps1
################################################################################ #.SYNOPSIS # Get-MECMDeviceCollectionPrimaryEmailAddresses.ps1 # Get the Primary User and email for all computers in a ConfigMgr device collection #.DESCRIPTION #.PARAMETER SiteCode # Specifies the ConfigMgr Site Code #.PARAMETER SiteServer # Specifies the ConfigMgr Primary Site Server #.PARAMETER CollectionName # Specifies the name of the ConfigMgr device Collection #.PARAMETER CollectionID # Specifies the ID of the ConfigMgr device Collection #.PARAMETER OutputFile # Specifies the full path and file name of the CSV file receiving the script output #.EXAMPLE # .\Get-MECMDeviceCollectionPrimaryEmailAddresses.ps1 -CollectionID USA001D9 -OutputFile U:\USA001D9.csv # Get the user information for a Collection ID and save the results to a CSV file !!! one two skip a few 99 and now the end !!! $PrimaryUsers | Format-Table -AutoSize If ($OutputFile) { $PrimaryUsers | Export-Csv -Path "filesystem::$OutputFile" -NoTypeInformation Write-Output "Exported results to [$OutputFile]" } Pop-Location
Here is a sample output on screen and in CSV.
ConfigMgr: Get primary users with email for a collection