Getting the Email Address of all Configuration Manager Users

Share on:

The following short and sweet snippet of PowerShell will extract the list of admins from your SCCM environment and then get their email addresses. At the end, you can dump $email into a text file, or perhaps set it to your clipboard to paste into Outlook.

 1# Script assumes you have CM Module Loaded
 2# Script assumes you have access to AD CmdLets.
 3
 4$users = Get-CMAdministrativeUser | Where-Object { $_.AccountType -ne 2 }
 5
 6$adUsers = @()
 7$index = 0
 8
 9ForEach($user in $users) {
10    $index++
11    Write-Progress -Activity "Getting Administrative Users from ConfigMgr ($index/$($users.count))" -Status $($user.DistinguishedName) -PercentComplete $($index/$($users.count)*100)
12    If(!$user.isGroup) { 
13        $adUsers += $user.DistinguishedName
14    } else {
15        $adUsers += $(Get-ADGroupMember $($user.DistinguishedName) -Recursive) | Select -ExpandProperty DistinguishedName
16    }
17}
18
19$adUsers = $adUsers | Select -Unique        # Users could be members of multiple groups, or listed directly plus in a group
20
21$email = @()
22$index = 0
23
24ForEach($user in $adUsers) {
25    $index++
26    Write-Progress -Activity "Getting Email Address ($index/$($adUsers.count))" -Status $($user) -PercentComplete $($index/$($adUsers.count)*100)
27    $email += Get-ADUser $user -Properties Mail | Select -ExpandProperty Mail
28}
29
30$email = $email | Select -Unique    # Two AD accounts with the same email?  Maybe?


No comments