-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e24adb6
commit e7686c1
Showing
14 changed files
with
753 additions
and
374 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
Manual resources/[powershell-datasource]_function-check-online-mailbox-exists.inputs.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[ | ||
{ | ||
"description": null, | ||
"translateDescription": false, | ||
"inputFieldType": 1, | ||
"key": "Name", | ||
"type": 0, | ||
"options": 1 | ||
}, | ||
{ | ||
"description": null, | ||
"translateDescription": false, | ||
"inputFieldType": 1, | ||
"key": "Alias", | ||
"type": 0, | ||
"options": 1 | ||
}, | ||
{ | ||
"description": null, | ||
"translateDescription": false, | ||
"inputFieldType": 1, | ||
"key": "Organization", | ||
"type": 0, | ||
"options": 1 | ||
} | ||
] |
6 changes: 6 additions & 0 deletions
6
Manual resources/[powershell-datasource]_function-check-online-mailbox-exists.model.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
{ | ||
"key": "text", | ||
"type": 0 | ||
} | ||
] |
138 changes: 138 additions & 0 deletions
138
Manual resources/[powershell-datasource]_function-check-online-mailbox-exists.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
####################################################################### | ||
# Template: RHo HelloID SA Powershell data source | ||
# Name: function-check-online-mailbox-exists | ||
# Date: 05-02-2024 | ||
####################################################################### | ||
|
||
# For basic information about powershell data sources see: | ||
# https://docs.helloid.com/en/service-automation/dynamic-forms/data-sources/powershell-data-sources.html | ||
|
||
# Service automation variables: | ||
# https://docs.helloid.com/en/service-automation/service-automation-variables.html | ||
|
||
#region init | ||
# Set TLS to accept TLS, TLS 1.1 and TLS 1.2 | ||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12 | ||
|
||
$VerbosePreference = "SilentlyContinue" | ||
$InformationPreference = "Continue" | ||
$WarningPreference = "Continue" | ||
|
||
# global variables (Automation --> Variable libary): | ||
$TenantId = $EntraTenantId | ||
$AppID = $EntraAppID | ||
$Secret = $EntraSecret | ||
$Organization = $EntraOrganization | ||
|
||
# variables configured in form: | ||
$Maildomain = $datasource.Organization.Maildomain | ||
$Name = $datasource.name | ||
$Alias = $datasource.alias | ||
$PrimarySmtpAddress = $Alias.Replace(" ", "") + "@$Maildomain" | ||
|
||
# PowerShell commands to import | ||
$commands = @("Get-User", "Get-Mailbox") | ||
#endregion init | ||
|
||
try { | ||
#region import module | ||
$actionMessage = "importing $moduleName module" | ||
|
||
$importModuleParams = @{ | ||
Name = "ExchangeOnlineManagement" | ||
Cmdlet = $commands | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Import-Module @importModuleParams | ||
#endregion import module | ||
|
||
#region create access token | ||
Write-Verbose "Creating Access Token" | ||
$actionMessage = "creating access token" | ||
|
||
$body = @{ | ||
grant_type = "client_credentials" | ||
client_id = "$AppID" | ||
client_secret = "$Secret" | ||
resource = "https://outlook.office365.com" | ||
} | ||
|
||
$exchangeAccessTokenParams = @{ | ||
Method = 'POST' | ||
Uri = "https://login.microsoftonline.com/$TenantId/oauth2/token" | ||
Body = $body | ||
ContentType = 'application/x-www-form-urlencoded' | ||
UseBasicParsing = $true | ||
} | ||
|
||
$accessToken = (Invoke-RestMethod @exchangeAccessTokenParams).access_token | ||
#endregion create access token | ||
|
||
#region connect to Exchange Online | ||
Write-Verbose "Connecting to Exchange Online" | ||
$actionMessage = "connecting to Exchange Online" | ||
|
||
$exchangeSessionParams = @{ | ||
Organization = $Organization | ||
AppID = $AppID | ||
AccessToken = $accessToken | ||
CommandName = $commands | ||
ShowBanner = $false | ||
ShowProgress = $false | ||
TrackPerformance = $false | ||
ErrorAction = 'Stop' | ||
} | ||
Connect-ExchangeOnline @exchangeSessionParams | ||
|
||
Write-Information "Successfully connected to Exchange Online" | ||
#endregion connect to Exchange Online | ||
|
||
#region check shared mailbox | ||
$actionMessage = "getting shared mailbox" | ||
|
||
$SharedMailboxParams = @{ | ||
Filter = "{Alias -eq '$Alias' -or Name -eq '$Name' -or PrimarySmtpAddress -eq '$PrimarySmtpAddress'}" | ||
# RecipientTypeDetails = 'SharedMailbox' | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
$SharedMailbox = Get-Mailbox @SharedMailboxParams | ||
|
||
if ([string]::IsNullOrEmpty($SharedMailbox)) { | ||
Write-Information "Shared Mailbox name [$Name] is available" | ||
$outputMessage = "Valid | Shared Mailbox name [$Name] is available" | ||
$returnObject = @{ | ||
text = $outputMessage | ||
} | ||
} | ||
else { | ||
Write-Information "Shared Mailbox [$Name] exists. Please try another name" | ||
$outputMessage = "Invalid | Shared Mailbox name [$Name] exists. Please try another name" | ||
$returnObject = @{ | ||
text = $outputMessage | ||
} | ||
} | ||
#endregion check shared mailbox | ||
} | ||
catch { | ||
$ex = $PSItem | ||
if ($($ex.Exception.GetType().FullName -eq 'Microsoft.PowerShell.Commands.HttpResponseException') -or | ||
$($ex.Exception.GetType().FullName -eq 'System.Net.WebException')) { | ||
$errorMessage = ($ex.ErrorDetails.Message | Convertfrom-json).error_description | ||
} | ||
else { | ||
$errorMessage = $($ex.Exception.message) | ||
} | ||
|
||
Write-Error "Error $actionMessage for Exchange Online shared mailbox [$Name]. Error: $errorMessage" | ||
|
||
$outputMessage = "Invalid | Error $actionMessage for Exchange Online shared mailbox [$Name]. Error: $errorMessage" | ||
$returnObject = @{ | ||
text = $outputMessage | ||
} | ||
} | ||
finally { | ||
Write-Output $returnObject | ||
} | ||
#endregion lookup |
10 changes: 10 additions & 0 deletions
10
...static-datasource]_Exchange-online-shared-mailbox-generate-table-mail-domains-create.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"Naam": "Enyoi", | ||
"Maildomain": "enyoi.org" | ||
}, | ||
{ | ||
"Naam": "Tools4ever", | ||
"Maildomain": "Tools4ever.com" | ||
} | ||
] |
10 changes: 10 additions & 0 deletions
10
...-datasource]_Exchange-online-shared-mailbox-generate-table-mail-domains-create.model.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"key": "Naam", | ||
"type": 0 | ||
}, | ||
{ | ||
"key": "Maildomain", | ||
"type": 0 | ||
} | ||
] |
10 changes: 0 additions & 10 deletions
10
Manual resources/[static-datasource]_Shared-mailbox-generate-table-mail-domains-create.json
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
...esources/[static-datasource]_Shared-mailbox-generate-table-mail-domains-create.model.json
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
Manual resources/[task]_Exchange Online - Shared Mailbox - Create.config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "Exchange Online - Shared Mailbox - Create", | ||
"runInCloud": false | ||
} |
169 changes: 169 additions & 0 deletions
169
Manual resources/[task]_Exchange Online - Shared Mailbox - Create.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
####################################################################### | ||
# Template: RHo HelloID SA Delegated form task | ||
# Name: Exchange Online Shared Mailbox - Create | ||
# Date: 02-05-2024 | ||
####################################################################### | ||
|
||
# For basic information about delegated form tasks see: | ||
# https://docs.helloid.com/en/service-automation/delegated-forms/delegated-form-powershell-scripts.html | ||
|
||
# Service automation variables: | ||
# https://docs.helloid.com/en/service-automation/service-automation-variables.html | ||
|
||
#region init | ||
|
||
# Set TLS to accept TLS, TLS 1.1 and TLS 1.2 | ||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12 | ||
|
||
$VerbosePreference = "SilentlyContinue" | ||
$InformationPreference = "Continue" | ||
$WarningPreference = "Continue" | ||
|
||
# global variables (Automation --> Variable libary): | ||
$TenantId = $EntraTenantId | ||
$AppID = $EntraAppID | ||
$Secret = $EntraSecret | ||
$Organization = $EntraOrganization | ||
|
||
# variables configured in form: | ||
$Maildomain = $form.organization.Maildomain | ||
$Name = $form.name | ||
$Alias = $form.alias | ||
|
||
# PowerShell commands to import | ||
$commands = @("Get-User", "New-Mailbox", "Set-Mailbox") | ||
#endregion init | ||
|
||
#region functions | ||
|
||
#endregion functions | ||
|
||
try { | ||
#region import module | ||
$actionMessage = "importing $moduleName module" | ||
|
||
$importModuleParams = @{ | ||
Name = "ExchangeOnlineManagement" | ||
Cmdlet = $commands | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Import-Module @importModuleParams | ||
#endregion import module | ||
|
||
#region create access token | ||
Write-Verbose "Creating Access Token" | ||
$actionMessage = "creating access token" | ||
|
||
$body = @{ | ||
grant_type = "client_credentials" | ||
client_id = "$AppID" | ||
client_secret = "$Secret" | ||
resource = "https://outlook.office365.com" | ||
} | ||
|
||
$exchangeAccessTokenParams = @{ | ||
Method = 'POST' | ||
Uri = "https://login.microsoftonline.com/$TenantId/oauth2/token" | ||
Body = $body | ||
ContentType = 'application/x-www-form-urlencoded' | ||
UseBasicParsing = $true | ||
} | ||
|
||
$accessToken = (Invoke-RestMethod @exchangeAccessTokenParams).access_token | ||
#endregion create access token | ||
|
||
#region connect to Exchange Online | ||
Write-Verbose "Connecting to Exchange Online" | ||
$actionMessage = "connecting to Exchange Online" | ||
|
||
$exchangeSessionParams = @{ | ||
Organization = $Organization | ||
AppID = $AppID | ||
AccessToken = $accessToken | ||
CommandName = $commands | ||
ShowBanner = $false | ||
ShowProgress = $false | ||
TrackPerformance = $false | ||
ErrorAction = 'Stop' | ||
} | ||
Connect-ExchangeOnline @exchangeSessionParams | ||
|
||
Write-Information "Successfully connected to Exchange Online" | ||
#endregion connect to Exchange Online | ||
|
||
#region create shared mailbox | ||
$actionMessage = "creating shared mailbox" | ||
$CreateMailboxParams = @{ | ||
Shared = $true | ||
Name = $Name | ||
DisplayName = $Name | ||
PrimarySmtpAddress = $Alias.Replace(" ", "") + "@$Maildomain" | ||
Alias = $Alias.Replace(" ", "") | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
New-Mailbox @CreateMailboxParams | ||
|
||
Write-Information "Shared Mailbox [$Name] created successfully" | ||
$Log = @{ | ||
Action = "CreateResource" # optional. ENUM (undefined = default) | ||
System = "Exchange Online" # optional (free format text) | ||
Message = "Shared Mailbox [$Name] created successfully" # required (free format text) | ||
IsError = $false # optional. Elastic reporting purposes only. (default = $false. $true = Executed action returned an error) | ||
TargetDisplayName = $Name # optional (free format text) | ||
TargetIdentifier = $([string]$Alias) # optional (free format text) | ||
} | ||
#send result back | ||
Write-Information -Tags "Audit" -MessageData $log | ||
#endregion create shared mailbox | ||
|
||
#region update shared mailbox | ||
$actionMessage = "updating shared mailbox" | ||
Start-Sleep -Seconds 10 | ||
|
||
$UpdateMailboxParams = @{ | ||
Identity = "$($CreateMailboxParams.PrimarySmtpAddress)" | ||
MessageCopyForSendOnBehalfEnabled = $true | ||
MessageCopyForSentAsEnabled = $true | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Set-Mailbox @UpdateMailboxParams | ||
|
||
Write-Information "Shared Mailbox [$Name] updated successfully" | ||
$Log = @{ | ||
Action = "CreateResource" # optional. ENUM (undefined = default) | ||
System = "Exchange Online" # optional (free format text) | ||
Message = "Shared Mailbox [$Name] updated successfully" # required (free format text) | ||
IsError = $false # optional. Elastic reporting purposes only. (default = $false. $true = Executed action returned an error) | ||
TargetDisplayName = $Name # optional (free format text) | ||
TargetIdentifier = $([string]$Alias) # optional (free format text) | ||
} | ||
#send result back | ||
Write-Information -Tags "Audit" -MessageData $log | ||
#endregion update shared mailbox | ||
} | ||
catch { | ||
$ex = $PSItem | ||
if ($($ex.Exception.GetType().FullName -eq 'Microsoft.PowerShell.Commands.HttpResponseException') -or | ||
$($ex.Exception.GetType().FullName -eq 'System.Net.WebException')) { | ||
$errorMessage = ($ex.ErrorDetails.Message | Convertfrom-json).error_description | ||
} | ||
else { | ||
$errorMessage = $($ex.Exception.message) | ||
} | ||
|
||
Write-Error "Error $actionMessage for Exchange Online shared mailbox [$Name]. Error: $errorMessage" | ||
|
||
$Log = @{ | ||
Action = "CreateResource" # optional. ENUM (undefined = default) | ||
System = "Exchange Online" # optional (free format text) | ||
Message = "Error $actionMessage for Exchange Online shared mailbox [$Name]" # required (free format text) | ||
IsError = $true # optional. Elastic reporting purposes only. (default = $false. $true = Executed action returned an error) | ||
TargetDisplayName = $Name # optional (free format text) | ||
TargetIdentifier = $([string]$Alias) # optional (free format text) | ||
} | ||
#send result back | ||
Write-Information -Tags "Audit" -MessageData $log | ||
} |
Oops, something went wrong.