Skip to content

Instantly share code, notes, and snippets.

@neerajks77
Created September 22, 2023 15:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neerajks77/6a22073c2d21419f54efb468b500238e to your computer and use it in GitHub Desktop.
Save neerajks77/6a22073c2d21419f54efb468b500238e to your computer and use it in GitHub Desktop.
###############################################
#Author:Neeraj Kumar
#Description:This script intakes the parameters from incoming ServiceNow Requests for setting the email size limit
#Date: 09/21/2023
####. ###########################################
param(
[parameter (mandatory = $false)]
[object] $WebhookData
)
# Enforcing validation of code
Set-StrictMode -Version Latest
Set-ExecutionPolicy RemoteSigned
if ($WebhookData) {
# If section for testing providing webhook data via the Azure portal
if (-Not $WebhookData.RequestBody) {
Write-Output 'No request body from test pane'
$WebhookData = (ConvertFrom-JSON -InputObject $WebhookData)
$params = (ConvertFrom-JSON -InputObject $WebhookData.RequestBody)
}
#$request = (ConvertFrom-JSON -InputObject $WebhookData.RequestBody)
$params = (ConvertFrom-JSON -InputObject $WebhookData.RequestBody)
}
Write-Output $params
[string] $UPIid = $params.emailid
[string] $IssueWarningQuota = $params.issue_warning_quota
[string] $ProhibitSendQuota = $params.prohibit_send_quota
[string] $ProhibitSendReceiveQuota = $params.prohibit_receive_quota
# use this function to set the mailbox size limit
function SetMailboxSize{
try{
if ($UPIid -match "^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$")
{
#Connect to Exchange Online
Connect-ExchangeOnline -AppId $AppId -CertificateThumbPrint $ThumbPrint -Organization $Organization -ShowBanner:$false -ShowProgress:$false #-ErrorAction Stop
[string] $GetEmail = Get-Mailbox -Identity $UPIid -ErrorAction SilentlyContinue
if (($GetEmail -eq "") -or ($GetEmail -eq $null)){
$Global:Outputs = "The email address provided does not exist. Please raise a new request with correct email id. The ticket has been marked as closed imcompleted."
$Global:Provisioningstate = "Failed"
$Global:RequestState = "Closed_Incomplete"
}
else{
Set-Mailbox -Identity $UPIid -IssueWarningQuota $IssueWarningQuota -ProhibitSendQuota $ProhibitSendQuota -ProhibitSendReceiveQuota $ProhibitSendReceiveQuota
$Global:Outputs = "Mailbox size has been changed for Email ID - " + $UPIid + ". Request has been Completed."
$Global:Provisioningstate = "Succeeded"
$Global:RequestState = "Closed_Complete"
}
}
else{
$Global:Outputs = "The email address provided is in the incorrect format. Please raise a new request with correct email id. The ticket has been marked as closed imcompleted."
$Global:Provisioningstate = "Failed"
$Global:RequestState = "Closed_Incomplete"
}
}
Catch{
$Global:Provisioningstate = "Failed"
$Global:RequestState = "Closed_Incomplete"
$Global:Outputs = $_.Exception.ToString()
$error[0] | Format-List -Force
}
}
# Initiate the variable here
##################################
[Boolean] $EmailExists = $true
[Boolean] $Global:MailboxSizeSet = $false
[string] $Thumbprint = Get-AutomationVariable -Name 'Cert_Thumbprint'
[string] $AppId = Get-AutomationVariable -Name 'AppID'
[string] $Organization = Get-AutomationVariable -Name 'Organization'
[string] $Global:Provisioningstate = ''
[string] $Global:Outputs = ' '
#####################################
# call the function to provision email id
#####################################
SetMailboxSize
################################################################# End Main Section ############################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment