-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateOktaProxyAddresses.ps1
107 lines (101 loc) · 4.15 KB
/
CreateOktaProxyAddresses.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$OktaGroupID,
[Parameter(Mandatory = $true)]
[string]
$OktaGroupName,
[Parameter(Mandatory = $false)]
[string]
$OutputPath = $PSScriptRoot
)
BEGIN {
$Global:ErrorActionPreference = 'STOP'
try {
Get-Command "Get-Mailbox" | Out-Null
}
catch {
Write-Error "Not connected to Exchange Online. You must connect to Exchange Online first."
exit
}
if (-not(Test-Path $OutputPath)){
throw "Output directory '$OutputPath' doesn't exist. Please create this directory and tyr again."
}
}
PROCESS {
Write-Verbose "Getting Okta group members for $OktaGroupID..."
$OktaGroupMembers = (oktaGetGroupMembersbyId -gid $OktaGroupID).Profile
$Total = $OktaGroupMembers | Measure-Object | Select-Object -ExpandProperty Count
Write-Verbose "Found $total members."
$i = 0
$Properties = @()
$OktaGroupMembers | ForEach-Object { $Properties += ($_ | Get-Member -Type NoteProperty).Name }
$Properties = $Properties | Sort-Object -Unique
$Results = @()
foreach ($User in $OktaGroupMembers) {
$Email = $user.secondEmail
Write-Progress -Activity "Exporting Proxy Addresses" -Status "User: $Email | Status: ($i / $total)" -PercentComplete "$(($i / $Total)*100)" -CurrentOperation "User: $Email"
$i++
$NewProxyAddresses = @($User.proxyAddresses)
if (-not $NewProxyAddresses) {
$NewProxyAddresses = @()
}
Write-Verbose "Getting mailbox for user $Email..."
try{
$MB = Get-MailBox $Email -ErrorAction Stop
}
Catch{
Write-Host "Can't find user $email in EXO. Skipping user." -ForegroundColor Red
continue
}
$NewProxyAddresses += "x500:$($MB.LegacyExchangeDN)"
$NewProxyAddresses += $MB.EmailAddresses | Where-Object { $_ -like "x500:*" } | ForEach-Object { $_ -creplace "^X500:", "x500:" }
$NewProxyAddresses = $NewProxyAddresses | Sort-Object -Unique
Write-Verbose "Creating results object..."
$Result = [PSCustomObject]@{
"login" = $User.login
"firstName" = $User.firstName
"lastName" = $User.lastName
"middleName" = $User.middleName
"honorificPrefix" = $User.honorificPrefix
"honorificSuffix" = $User.honorificSuffix
"email" = $User.email
"title" = $User.title
"displayName" = $User.displayName
"nickName" = $User.nickName
"profileUrl" = $User.profileUrl
"secondEmail" = $User.secondEmail
"mobilePhone" = $User.mobilePhone
"primaryPhone" = $User.primaryPhone
"streetAddress" = $User.streetAddress
"city" = $User.city
"state" = $User.state
"zipCode" = $User.zipCode
"countryCode" = $User.countryCode
"postalAddress" = $User.postalAddress
"preferredLanguage" = $User.preferredLanguage
"locale" = $User.locale
"timezone" = $User.timezone
"userType" = $User.userType
"employeeNumber" = $User.employeeNumber
"costCenter" = $User.costCenter
"organization" = $User.organization
"division" = $User.division
"department" = $User.department
"managerId" = $User.managerId
"manager" = $User.manager
"proxyAddresses" = $NewProxyAddresses -join ";"
}
Write-Verbose "Adding to results..."
$Results += $Result
}
}
END {
$DATE = get-date -Format yyyy-MM-dd_HH.mm
$OutputName = "Okta_$($OktaGroupName)_$($Date).csv"
$OutputName = Join-Path $OutputPath $OutputName
Write-Verbose "Exporting results to $OutputName..."
$Results | Export-Csv -NoTypeInformation -LiteralPath $OutputName
Write-Host "File saved to: $OutputName" -ForegroundColor Green
}