EWS Extension Online Powershell v2 Deprecated

Deprecated. Use ***EWS Extension Online Powershell v3*** instead.

Email · Microsoft Exchange Online

Details

IDEWS Extension Online Powershell v2
ProviderMicrosoft
CategoryEmail
From Version5.5.0
Docker Imagedemisto/pwsh-exchangev3:1.0.0.49863
Supported ModulesAgentix Cloud Runtime Security Cloud Posture Security XSIAM EDR Cortex Cloud

README

Deprecated. Use EWS Extension Online Powershell v3 instead.

Use the EWS Extension Online Powershell v2 integration to get information about mailboxes and users in your organization.
This integration was integrated and tested with version v2 of EWS Extension Online Powershell v2

Note: This integration does not replace the O365 - EWS - Extension integration, but an additional EWS extension integration
which utilizes the EXO v2 module.

Configure EWS Extension Online Powershell v2 in Cortex

Parameter Description Required
Exchange Online URL   True
Certificate A pfx certificate encoded in Base64. True
The organization used in app-only authentication.   True
The application ID from the Azure portal   True

Commands

You can execute these commands from the CLI, as part of an automation, or in a playbook.
After you successfully execute a command, a DBot message appears in the War Room with the command details.

ews-mailbox-list


Displays mailbox objects and attributes, populate property pages, or supplies mailbox information to other tasks.

Base Command

ews-mailbox-list

Input

Argument Name Description Required
identity The identity of the mailbox you want to view. Optional
organizational_unit The object’s location in Active Directory by which to filter the results. Optional
primary_smtp_address The primary SMTP email address of the mailbox you want to view. Cannot be used with the user_principal_name argument. Can be retrieved using the ews-user-list command. Optional
user_principal_name The UPN of the mailbox you want to view. Cannot be used with the primary_smtp_address argument. Can be retrieved using the ews-user-list command. Optional
property_sets A comma-separated list of property sets to fetch. These property sets will supplement the outputs of this integration. Default is “Minimum”. Available properties are: “All”, “Minimum”, “AddressList”, “Archive”, “Audit”, “Delivery”, “Hold”, “Moderation”, “Move”, “Policy”, “PublicFolder”, “Quota”, “Resource”, “Retention”, “SCL”, “SoftDelete”, “StatisticsSeed”. Optional
limit The maximum number of results to retrieve. Default is 10. Default is 10. Optional

Context Output

Path Type Description
EWS.Mailbox.EmailAddresses String Email addresses of the mailbox.
EWS.Mailbox.AuditBypassEnabled Boolean Whether audit bypass is enabled.
EWS.Mailbox.DistinguishedName String Distinguished name of the mailbox.
EWS.Mailbox.ExchangeObjectId String Exchange object ID of the mailbox.
EWS.Mailbox.ExchangeVersion String Exchange version of the mailbox.
EWS.Mailbox.Guid String GUID of the mailbox.
EWS.Mailbox.Id String ID of the mailbox.
EWS.Mailbox.Identity String Identity of the mailbox.
EWS.Mailbox.IsValid Boolean Whether the mailbox is valid.
EWS.Mailbox.Name String Name of the mailbox.
EWS.Mailbox.ObjectCategory String Object category of the mailbox.
EWS.Mailbox.ObjectClass String Object class of the mailbox.
EWS.Mailbox.ObjectId String Object ID of the of the mailbox.
EWS.Mailbox.ObjectState String Object state of the mailbox.
EWS.Mailbox.OrganizationId String Organization ID of the mailbox.
EWS.Mailbox.OriginatingServer String Originating server of the mailbox.
EWS.Mailbox.PSComputerName String PowerShell computer name of the mailbox.
EWS.Mailbox.PSShowComputerName Boolean PowerShell show computer name of the mailbox.
EWS.Mailbox.RunspaceId String Run space ID of the mailbox.
EWS.Mailbox.WhenChanged Date Local time of when the mailbox was last changed.
EWS.Mailbox.WhenChangedUTC Date UTC time of when the mailbox was last changed.
EWS.Mailbox.WhenCreated Date Local time of when the mailbox was created.
EWS.Mailbox.WhenCreatedUTC Date UTC time of when the mailbox was created.

Command Example

!ews-mailbox-list limit=1

Context Example

{
    "EWS": {
        "Mailbox": {
            "Alias": "user",
            "DisplayName": "User User",
            "DistinguishedName": "CN=user,OU=example.com,OU=Microsoft Exchange Hosted Organizations,DC=EURPR07A005,DC=PROD,DC=OUTLOOK,DC=COM",
            "EmailAddresses": [
                "SPO:SPO_SPO0@SPO_SPO1",
                "SIP:user@example.com",
                "SMTP:user@example.com"
            ],
            "ExchangeVersion": "0.20 (15.0.0)",
            "ExternalDirectoryObjectId": "<ExternalDirectoryObjectId>",
            "Guid": "<Guid>",
            "Id": "user",
            "Identity": "user",
            "Name": "user",
            "OrganizationId": "EURPR07A005.PROD.OUTLOOK.COM/Microsoft Exchange Hosted Organizations/example.com - EURPR07A005.PROD.OUTLOOK.COM/ConfigurationUnits/example.com/Configuration",
            "PrimarySmtpAddress": "user@example.com",
            "RecipientType": "UserMailbox",
            "RecipientTypeDetails": "UserMailbox",
            "UserPrincipalName": "user@example.com"
        }
    }
}

Human Readable Output

Results of ews-mailbox-list

Alias DisplayName DistinguishedName EmailAddresses ExchangeVersion ExternalDirectoryObjectId Guid Id Identity Name OrganizationId PrimarySmtpAddress RecipientType RecipientTypeDetails UserPrincipalName
“user” “User User” “CN=user,OU=example.com,OU=Microsoft Exchange Hosted Organizations,DC=EURPR07A005,DC=PROD,DC=OUTLOOK,DC=COM” [“SPO:SPO_cac4b654-5fcf-44f0-818e-479cf8ae42ac@SPO_SP01”,”SIP:user@example.com”,”SMTP:user@example.com”] “0.20 (15.0.0)” “3fa9f28b-eb0e-463a-ba7b-8089fe9991e2” {“value”:”042e60ea-0683-41a2-a149-ca4b682dcdda”,”Guid”:”042e60ea-0683-41a2-a149-ca4b682dcdda”} “user” “user” “user” “EURPR07A005.PROD.OUTLOOK.COM/Microsoft Exchange Hosted Organizations/example.com - EURPR07A005.PROD.OUTLOOK.COM/ConfigurationUnits/example.com/Configuration” “user@example.com” “UserMailbox” “UserMailbox” “user@example.com”

ews-cas-mailbox-list


Displays Client Access settings that are configured on mailboxes.

Base Command

ews-cas-mailbox-list

Input

Argument Name Description Required
identity The identity of the mailbox you want to view. Optional
organizational_unit The object’s location in Active Directory by which to filter the results. Optional
primary_smtp_address The primary SMTP email address of the mailbox you want to view. Cannot be used with the user_principal_name argument. Can be retrieved using the ews-user-list command. Optional
user_principal_name The UPN of the mailbox you want to view. Cannot be used with the primary_smtp_address argument. Can be retrieved using the ews-user-list command. Optional
limit The maximum number of results to retrieve. Default is 10. Default is 10. Optional

Context Output

Path Type Description
EWS.CASMailbox.ActiveSyncEnabled Boolean Whether active sync is enabled.
EWS.CASMailbox.DisplayName String The display name of the mailbox.
EWS.CASMailbox.ECPEnabled Boolean Whether the Exchange Control Panel (ECP) is enabled.
EWS.CASMailbox.EmailAddresses String The email addresses retrieved.
EWS.CASMailbox.EwsEnabled Boolean Whether the Exchange Web Services (EWS) is enabled.
EWS.CASMailbox.ExchangeVersion String Exchange version of the client access server mailbox.
EWS.CASMailbox.ExternalDirectoryObjectId String External directory object ID of the client access server mailbox.
EWS.CASMailbox.Guid String The GUID of the client access server mailbox.
EWS.CASMailbox.Identity String Identity of the client access server mailbox.
EWS.CASMailbox.ImapEnabled Boolean Whether the Internet Message Access Protocol (IMAP) is enabled.
EWS.CASMailbox.MAPIEnabled Boolean Whether the Messaging Application Programming Interface is enabled.
EWS.CASMailbox.Name String Name of the client access server mailbox.
EWS.CASMailbox.OWAEnabled Boolean Whether Outlook on the web (OWA) is enabled.
EWS.CASMailbox.OrganizationId String Organization ID
EWS.CASMailbox.PopEnabled Boolean Whether Post Office Protocol (POP) is enabled.
EWS.CASMailbox.PrimarySmtpAddress String Primary SMTP address.
EWS.CASMailbox.ServerLegacyDN String Server legacy distinguished name (DN).

Command Example

!ews-cas-mailbox-list limit=1

Context Example

{
    "EWS": {
        "CASMailbox": {
            "ActiveSyncEnabled": true,
            "DisplayName": "User User",
            "ECPEnabled": true,
            "EmailAddresses": [
                "SPO:SPO_SPO0@SPO_SPO1",
                "SIP:user@example.com",
                "SMTP:user@example.com"
            ],
            "EwsEnabled": true,
            "ExchangeVersion": "0.20 (15.0.0)",
            "ExternalDirectoryObjectId": "<ExternalDirectoryObjectId>",
            "Guid": "<Guid>",
            "Identity": "user",
            "ImapEnabled": true,
            "MAPIEnabled": true,
            "Name": "user",
            "OWAEnabled": true,
            "OrganizationId": "EURPR07A005.PROD.OUTLOOK.COM/Microsoft Exchange Hosted Organizations/example.com - EURPR07A005.PROD.OUTLOOK.COM/ConfigurationUnits/example.com/Configuration",
            "PopEnabled": true,
            "PrimarySmtpAddress": "user@example.com",
            "ServerLegacyDN": "/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=DBXPR07MB383"
        }
    }
}

Human Readable Output

Results of ews-cas-mailbox-list

ActiveSyncEnabled DisplayName ECPEnabled EmailAddresses EwsEnabled ExchangeVersion ExternalDirectoryObjectId Guid Identity ImapEnabled MAPIEnabled Name OrganizationId OWAEnabled PopEnabled PrimarySmtpAddress ServerLegacyDN
true “User User” true [“SPO:SPO_cac4b654-5fcf-44f0-818e-479cf8ae42ac@SPO_SP01”,”SIP:user@example.com”,”SMTP:user@example.com”] true “0.20 (15.0.0)” “3fa9f28b-eb0e-463a-ba7b-8089fe9991e2” {“value”:”042e60ea-0683-41a2-a149-ca4b682dcdda”,”Guid”:”042e60ea-0683-41a2-a149-ca4b682dcdda”} “user” true true “user” “EURPR07A005.PROD.OUTLOOK.COM/Microsoft Exchange Hosted Organizations/example.com - EURPR07A005.PROD.OUTLOOK.COM/ConfigurationUnits/example.com/Configuration” true true “user@example.com” “/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=DBXPR07MB383

ews-mailbox-permission-list


Retrieves permissions on a mailbox.

Base Command

ews-mailbox-permission-list

Input

Argument Name Description Required
identity The identity of the mailbox you want to view. Required

Context Output

Path Type Description
EWS.MailboxPermission.Identity String The specified identity of the mailbox.
EWS.MailboxPermission.Permission.AccessRights String Access rights of the mailbox.
EWS.MailboxPermission.Permission.Deny.IsPresent Boolean Whether permission is denied.
EWS.MailboxPermission.Permission.Identity String The permission identity.
EWS.MailboxPermission.Permission.InheritanceType String Permission inheritance type.
EWS.MailboxPermission.Permission.IsInherited Boolean Whether permission is inherited.
EWS.MailboxPermission.Permission.User String The permission of the user.

Command Example

!ews-mailbox-permission-list identity=user

Context Example

{
    "EWS": {
        "MailboxPermission": {
            "Identity": "user",
            "Permission": {
                "AccessRights": [
                    "FullAccess",
                    "ReadPermission"
                ],
                "Deny": {
                    "IsPresent": false
                },
                "Identity": "user",
                "InheritanceType": "All",
                "IsInherited": false,
                "User": "NT AUTHORITY\\SELF"
            }
        }
    }
}

Human Readable Output

Results of ews-mailbox-permission-list

AccessRights Deny Identity InheritanceType IsInherited User
[“FullAccess”,”ReadPermission”] {“IsPresent”:false} “user” “All” false “NT AUTHORITY\SELF”

ews-recipient-permission-list


Displays information about SendAs permissions that are configured for users.

Base Command

ews-recipient-permission-list

Input

Argument Name Description Required
identity The identity of the mailbox you want to view. Optional
limit The maximum number of results to retrieve. Default is 10. Default is 10. Optional

Context Output

Path Type Description
EWS.RecipientPermission.AccessControlType String Access control type of the recipient permission.
EWS.RecipientPermission.AccessRights Number Access rights of the recipient permission.
EWS.RecipientPermission.Identity String Identity of the recipient permission.
EWS.RecipientPermission.InheritanceType String Inheritance type of the recipient permission.
EWS.RecipientPermission.IsInherited Boolean Whether the recipient permission is inherited.
EWS.RecipientPermission.Trustee String Trustee of the recipient permission.

Command Example

!ews-recipient-permission-list identity=<Guid>

Context Example

{
    "EWS": {
        "RecipientPermission": {
            "AccessControlType": "Allow",
            "AccessRights": [
                1
            ],
            "Identity": "user",
            "InheritanceType": "None",
            "IsInherited": false,
            "Trustee": "NT AUTHORITY\\SELF"
        }
    }
}

Human Readable Output

Results of ews-mailbox-permission-list

AccessRights Deny Identity InheritanceType IsInherited User
[“FullAccess”,”ReadPermission”] {“IsPresent”:false} “user” “All” false “NT AUTHORITY\SELF”

ews-recipient-list


Displays existing recipient objects in your organization. This command returns all mail-enabled objects (for example, mailboxes, mail users, mail contacts, and distribution groups).

Base Command

ews-recipient-list

Input

Argument Name Description Required
identity The identity of the mailbox you want to view. Optional
limit The maximum number of results to retrieve. Default is 10. Default is 10. Optional

Context Output

Path Type Description
EWS.Recipient.Alias String Recipient alias.
EWS.Recipient.DisplayName String Recipient display name.
EWS.Recipient.DistinguishedName String Recipient distinguished name.
EWS.Recipient.EmailAddresses String Recipient email addresses.
EWS.Recipient.ExchangeVersion String Recipient exchange version.
EWS.Recipient.ExternalDirectoryObjectId String Recipient external directory object ID.
EWS.Recipient.Identity String Recipient identity.
EWS.Recipient.Name String Recipient name.
EWS.Recipient.OrganizationId String Recipient organization ID.
EWS.Recipient.PrimarySmtpAddress String Recipient primary SMTP address.
EWS.Recipient.RecipientType String Recipient type.
EWS.Recipient.RecipientTypeDetails String Recipient type details.

Command Example

!ews-recipient-list identity=<ExternalDirectoryObjectId>

Context Example

{
    "EWS": {
        "Recipient": {
            "Alias": "user",
            "DisplayName": "User User",
            "DistinguishedName": "CN=user,OU=example.com,OU=Microsoft Exchange Hosted Organizations,DC=EURPR07A005,DC=PROD,DC=OUTLOOK,DC=COM",
            "EmailAddresses": [
                "SPO:SPO_SPO0@SPO_SPO1",
                "SIP:user@example.com",
                "SMTP:user@example.com"
            ],
            "ExchangeVersion": "0.20 (15.0.0)",
            "ExternalDirectoryObjectId": "<ExternalDirectoryObjectId>",
            "Identity": "user",
            "Name": "user",
            "OrganizationId": "EURPR07A005.PROD.OUTLOOK.COM/Microsoft Exchange Hosted Organizations/example.com - EURPR07A005.PROD.OUTLOOK.COM/ConfigurationUnits/example.com/Configuration",
            "PrimarySmtpAddress": "user@example.com",
            "RecipientType": "UserMailbox",
            "RecipientTypeDetails": "UserMailbox"
        }
    }
}

Human Readable Output

Results of ews-recipient-list

Alias DisplayName DistinguishedName EmailAddresses ExchangeVersion ExternalDirectoryObjectId Identity Name OrganizationId PrimarySmtpAddress RecipientType RecipientTypeDetails
“user” “user” “CN=user_Identity,OU=example.com,OU=Microsoft Exchange Hosted Organizations,DC=EURPR07A005,DC=PROD,DC=OUTLOOK,DC=COM” [“SPO:SPO_SP00@SPO_SP01”,”SMTP:user@example.com”] “0.10 (14.0.100)” “Identity” “user_Identity” “user_Identity” “EURPR07A005.PROD.OUTLOOK.COM/Microsoft Exchange Hosted Organizations/example.com - EURPR07A005.PROD.OUTLOOK.COM/ConfigurationUnits/example.com/Configuration” “user@example.com” “MailUniversalDistributionGroup” “GroupMailbox”

ews-new-tenant-allow-block-list-items


Add new items to the Tenant Allow/Block Lists. Uses PowerShell New-TenantAllowBlockListItems cmdlet.

Official PowerShell cmdlet documentation here

Base Command

ews-new-tenant-allow-block-list-items

Input

Argument Name Description Required
entries Entries to add to the list. Separate multiple entries with a comma (e.g. “Item1,Item2”). Required
list_type List type to add items to. Required
list_subtype List subtype to add items to. Optional
action Action to set for new entries Required
notes Notes to include on new list entries Optional
expiration_date Enter a specific date and time for the new entries to expire using format “YYYY-MM-DD HH:MM:SSz” for UTC time. Alternately, a PowerShell GetDate statement can be used. Optional
no_expiration Specify whether to create list entries with no expiration date. Cannot be used with “expiration_date”. If left false and no expiration date is set, default of 30 days will be used. Optional

Context Output

Path Type Description
EWS.NewTenantBlocks.Action String List type (‘Block’ or ‘Allow’)
EWS.NewTenantBlocks.EntryValueHash String Entry Value Hash
EWS.NewTenantBlocks.Error String Error (if any) returned by remote command
EWS.NewTenantBlocks.ExpirationDate String DateTime the entry will expire and be removed
EWS.NewTenantBlocks.Identity String Unique identifier for the entry
EWS.NewTenantBlocks.LastModifiedDateTime String DateTime of last modification
EWS.NewTenantBlocks.ListSubType String List sub type (Tenant or AdvancedDelivery)
EWS.NewTenantBlocks.ModifiedBy String User / App Registration which last modified this entry
EWS.NewTenantBlocks.Notes String Custom notes added to the entry.
EWS.NewTenantBlocks.ObjectState String State of the object (e.g. New/Modified/Deleted)
EWS.NewTenantBlocks.PSComputerName String Name of Remote Powershell endpoint
EWS.NewTenantBlocks.PSShowComputerName Bool Flag whether or not remote computer name is shown in PS prompt
EWS.NewTenantBlocks.RunspaceId String RunspaceID of the entry
EWS.NewTenantBlocks.SubmissionID String SubmissionID of the entry
EWS.NewTenantBlocks.SysManaged Bool SysManaged property of the entry
EWS.NewTenantBlocks.Value String The value of the new entry created

Command Example

!ews-new-tenant-allow-block-list-items action=Block list_type=sender entries="attacker@phishingsite.com" notes="Email observed in a phishing campaign."

Context Example

{
    "Action": "Block",
    "EntryValueHash": "d568L6iokOxrYqB2L1CxcKy6S6A/tCDoQQJal33AFWo=",
    "Error": null,
    "ExpirationDate": "2022-06-15T19:30:52.6071551Z",
    "Identity": "RgAAAAAuoyIuRcZsTKgZbIQyJWZUBwA02rlnO0nOR5RO-QI-xRP9AAAAAAEVAAA02rlnO0nOR5RO-QI-xRP9AAADfzPhAAAA0",
    "LastModifiedDateTime": "2022-05-16T19:30:52.7320883Z",
    "ListSubType": "Tenant",
    "ModifiedBy": "",
    "Notes": "Email observed in a phishing campaign.",
    "ObjectState": "New",
    "PSComputerName": "outlook.office365.com",
    "PSShowComputerName": false,
    "RunspaceId": "fe0186a8-6ce6-487d-bd65-a9869f60ffcd",
    "SubmissionID": "",
    "SysManaged": false,
    "Value": "attacker@phishingsite.com"
}

Human Readable Output

Results of ews-new-tenant-allow-block-list-items

Action EntryValueHash Error ExpirationDate Identity LastModifiedDateTime ListSubType ModifiedBy Notes ObjectState PSComputerName PSShowComputerName RunspaceId SubmissionID SysManaged Value
Block d568L6iokOxrYqB2L1CxcKy6S6A/tCDoQQJal33AFWo=   {“value”:”2022-06-15T19:34:01.2028448Z”,”DateTime”:”Wednesday, June 15, 2022 7:34:01 PM”} RgAAAAAuoyIuRcZsTKgZbIQyJWZUBwA02rlnO0nOR5RO-QI-xRP9AAAAAAEVAAA02rlnO0nOR5RO-QI-xRP9AAADfzPiAAAA0 {“value”:”2022-05-16T19:34:01.2652934Z”,”DateTime”:”Monday, May 16, 2022 7:34:01 PM”} Tenant   Email observed in a phishing campaign. New outlook.office365.com false {“value”:”8f736b87-f951-4b6b-aa21-e358720c44e3”,”Guid”:”8f736b87-f951-4b6b-aa21-e358720c44e3”}   false attacker@phishingsite.com

ews-get-tenant-allow-block-list-items


Retrieve current Tenant Allow/Block List items. Uses Get-TenantAllowBlockListItems cmdlet.

Official PowerShell cmdlet documentation here

Base Command

ews-get-tenant-allow-block-list-items

Input

Argument Name Description Required
list_type List type to retrieve items from. Required
list_subtype List subtype to retrieve items from. Optional
action Action to filter entries by. Required
expiration_date Enter a specific date and time to filter entries by using format “YYYY-MM-DD HH:MM:SSz” for UTC time. Alternately, a PowerShell GetDate statement can be used. Optional
no_expiration Filter list items that are set to never expire. Optional
entry Specif8ic entry value to retrieve. Optional

Context Output

Path Type Description
EWS.CurrentTenantBlocks.Action String List type (‘Block’ or ‘Allow’)
EWS.CurrentTenantBlocks.EntryValueHash String Entry Value Hash
EWS.CurrentTenantBlocks.Error Bool Error (if any) returned by remote command
EWS.CurrentTenantBlocks.ExpirationDate String DateTime the entry will expire and be removed
EWS.CurrentTenantBlocks.Identity String Unique identifier for the entry
EWS.CurrentTenantBlocks.LastModifiedDateTime String DateTime of last modification
EWS.CurrentTenantBlocks.ListSubType String List sub type (Tenant or AdvancedDelivery)
EWS.CurrentTenantBlocks.ModifiedBy String User / App Registration which last modified this entry
EWS.CurrentTenantBlocks.Notes String Custom notes added to the entry.
EWS.CurrentTenantBlocks.ObjectState String State of the object (e.g. New/Modified/Deleted)
EWS.CurrentTenantBlocks.PSComputerName String Name of Remote Powershell endpoint
EWS.CurrentTenantBlocks.PSShowComputerName Bool Flag whether or not remote computer name is shown in PS prompt
EWS.CurrentTenantBlocks.RunspaceId String RunspaceID of the entry
EWS.CurrentTenantBlocks.SubmissionID String SubmissionID of the entry
EWS.CurrentTenantBlocks.SysManaged Bool SysManaged property of the entry
EWS.CurrentTenantBlocks.Value String The value of the new entry created

Command Example

!ews-get-tenant-allow-block-list-items action=Block list_type=sender

Context Example

[
    {
        "Action": "Block",
        "EntryValueHash": "d568L6iokOxrYqB2L1CxcKy6S6A/tCDoQQJal33AFWo=",
        "Error": null,
        "ExpirationDate": "2022-06-15T19:34:01.2028448Z",
        "Identity": "RgAAAAAuoyIuRcZsTKgZbIQyJWZUBwA02rlnO0nOR5RO-QI-xRP9AAAAAAEVAAA02rlnO0nOR5RO-QI-xRP9AAADfzPiAAAA0",
        "LastModifiedDateTime": "2022-05-16T19:34:01.2652934Z",
        "ListSubType": "Tenant",
        "ModifiedBy": "",
        "Notes": "Email observed in a phishing campaign.",
        "ObjectState": "Unchanged",
        "PSComputerName": "outlook.office365.com",
        "PSShowComputerName": false,
        "RunspaceId": "010da4cf-2d47-4b8a-a882-4bd6885faff1",
        "SubmissionID": "",
        "SysManaged": false,
        "Value": "attacker@phishingsite.com"
    }
]

Human Readable Output

Results of ews-get-tenant-allow-block-list-items

Action EntryValueHash Error ExpirationDate Identity LastModifiedDateTime ListSubType ModifiedBy Notes ObjectState PSComputerName PSShowComputerName RunspaceId SubmissionID SysManaged Value
Block d568L6iokOxrYqB2L1CxcKy6S6A/tCDoQQJal33AFWo=   {“value”:”2022-06-15T19:34:01.2028448Z”,”DateTime”:”Wednesday, June 15, 2022 7:34:01 PM”} RgAAAAAuoyIuRcZsTKgZbIQyJWZUBwA02rlnO0nOR5RO-QI-xRP9AAAAAAEVAAA02rlnO0nOR5RO-QI-xRP9AAADfzPiAAAA0 {“value”:”2022-05-16T19:34:01.2652934Z”,”DateTime”:”Monday, May 16, 2022 7:34:01 PM”} Tenant   Email observed in a phishing campaign. Unchanged outlook.office365.com false {“value”:”feada07c-99b7-48e9-a562-a755073522ff”,”Guid”:”feada07c-99b7-48e9-a562-a755073522ff”}   false attacker@phishingsite.com

ews-get-tenant-allow-block-list-count


Retrieve current count of defined Tenant Allow/Block List items. Uses Get-TenantAllowBlockListItems cmdlet.

Official PowerShell cmdlet documentation here

Base Command

ews-get-tenant-allow-block-list-count

Input

Argument Name Description Required
list_type List type to retrieve items from. Optional
list_subtype List subtype to retrieve items from. Optional

Context Output

Path Type Description
EWS.CurrentListCount.Count Number Number of entries presently in the specified list
EWS.CurrentListCount.ListSubType String List sub type (Tenant or AdvancedDelivery)
EWS.CurrentListCount.ListType String List type

Command Example

!ews-get-tenant-allow-block-list-count list_type=sender

Context Example

{
    "Count": 2,
    "ListSubType": "Tenant",
    "ListType": "sender"
}

Human Readable Output

Results of ews-get-tenant-allow-block-list-count

Count ListSubType ListType
2 Tenant sender

ews-remove-tenant-allow-block-list-items


Remove items from the Tenant Allow/Block Lists. You can delete items by their value or by unique ID. Uses PowerShell cmdlet Remove-TenantAllowBlockListItems cmdlet.

Official PowerShell cmdlet documentation here

Base Command

ews-remove-tenant-allow-block-list-items

Input

Argument Name Description Required
entries Entries to remove from the list. Either use this OR ‘ids’ to specify items to remove. Separate multiple entries with a comma (e.g. “Item1,Item2”). Optional
ids Entry IDs to remove from the list. Either use this OR ‘entries’ to specify items to remove. Separate multiple entries with a comma (e.g. “Item1,Item2”). Optional
list_type List type to remove items from. Required
list_subtype List subtype to remove items from. Optional

Context Output

Path Type Description
EWS.RemovedTenantBlocks.Action String Action
EWS.RemovedTenantBlocks.EntryValueHash String Null for deleted items.
EWS.RemovedTenantBlocks.Error String Null for deleted items.
EWS.RemovedTenantBlocks.ExpirationDate String Null for deleted items.
EWS.RemovedTenantBlocks.Identity String Blank for deleted items.
EWS.RemovedTenantBlocks.LastModifiedDateTime String Null for deleted items.
EWS.RemovedTenantBlocks.ListSubType String Null for deleted items.
EWS.RemovedTenantBlocks.ModifiedBy String Null for deleted items.
EWS.RemovedTenantBlocks.Notes String Null for deleted items.
EWS.RemovedTenantBlocks.ObjectState String State of the object (Deleted)
EWS.RemovedTenantBlocks.PSComputerName String Name of Remote Powershell endpoint
EWS.RemovedTenantBlocks.PSShowComputerName Bool Flag whether or not remote computer name is shown in PS prompt
EWS.RemovedTenantBlocks.RunspaceId String RunspaceID of the entry
EWS.RemovedTenantBlocks.SubmissionID String SubmissionID of the entry
EWS.RemovedTenantBlocks.SysManaged Bool SysManaged property of the entry
EWS.RemovedTenantBlocks.Value String The value of the entry that was removed

Command Example

!ews-remove-tenant-allow-block-list-items list_type=sender entries="attacker2@phishingsite.com"

Context Example

{
    "Action": "0",
    "EntryValueHash": null,
    "Error": null,
    "ExpirationDate": null,
    "Identity": "",
    "LastModifiedDateTime": null,
    "ListSubType": null,
    "ModifiedBy": null,
    "Notes": null,
    "ObjectState": "Deleted",
    "PSComputerName": "outlook.office365.com",
    "PSShowComputerName": false,
    "RunspaceId": "efa88be5-7342-4b77-af2f-99dd2d914300",
    "SubmissionID": null,
    "SysManaged": null,
    "Value": "attacker2@phishingsite.com"
}

Human Readable Output

Results of ews-remove-tenant-allow-block-list-items

Action EntryValueHash Error ExpirationDate Identity LastModifiedDateTime ListSubType ModifiedBy Notes ObjectState PSComputerName PSShowComputerName RunspaceId SubmissionID SysManaged Value
0                 Deleted outlook.office365.com false {“value”:”cd58060e-d033-4cdb-814e-9f9748fdf78c”,”Guid”:”cd58060e-d033-4cdb-814e-9f9748fdf78c”}     attacker@phishingsite.com

Configuration parameters

  • url — Exchange Online URL (required)
  • certificate — (required)
  • password — (required)
  • organization — The organization used in app-only authentication. (required)
  • app_id — The application ID from the Azure portal (required)

Commands (9)

  • ews-cas-mailbox-list

    Displays Client Access settings that are configured on mailboxes.

  • ews-get-tenant-allow-block-list-count

    Retrieve current count of defined Tenant Allow/Block List items. Uses Get-TenantAllowBlockListItems cmdlet.

  • ews-get-tenant-allow-block-list-items

    Retrieve current Tenant Allow/Block List items. Uses Get-TenantAllowBlockListItems cmdlet.

  • ews-mailbox-list

    Displays mailbox objects and attributes, populate property pages, or supplies mailbox information to other tasks.

  • ews-mailbox-permission-list

    Retrieves permissions on a mailbox.

  • ews-new-tenant-allow-block-list-items

    Add new items to the Tenant Allow/Block Lists. Uses PowerShell New-TenantAllowBlockListItems cmdlet.

  • ews-recipient-list

    Displays existing recipient objects in your organization. This command returns all mail-enabled objects (for example, mailboxes, mail users, mail contacts, and distribution groups).

  • ews-recipient-permission-list

    Displays information about SendAs permissions that are configured for users.

  • ews-remove-tenant-allow-block-list-items

    Remove items from the Tenant Allow/Block Lists. You can delete items by their value or by unique ID. Uses PowerShell cmdlet Remove-TenantAllowBlockListItems cmdlet.

. $PSScriptRoot\CommonServerPowerShell.ps1
<# IMPORTANT NOTICE
# When conencting to ExchangeOnline - only needed command between CreateSession
# and DisconnectSession and let also the `finally` term to disconnect (it will do nothing if everything is fine).
# This will reduce the time sessions are opened between Exchange and the server and will create
# less problems.
# DO NOT USE ONE FINALLY STATEMENT: we don't know if and when it'll be executed and anyway it the DisconnectSession
# should be called before returning results to the server.
#>
Import-Module ExchangeOnlineManagement

# Disable PowerShell progress bars, as they aren't helpful in a non-interactive script
$Global:ProgressPreference = 'SilentlyContinue'

$COMMAND_PREFIX = "ews"
$INTEGRATION_ENTRY_CONTEXT = "EWS"

class ExchangeOnlinePowershellV2Client
{
    [string]$url
    [System.Security.Cryptography.X509Certificates.X509Certificate2]$certificate
    [string]$organization
    [string]$app_id
    [SecureString]$password
    ExchangeOnlinePowershellV2Client(
            [string]$url,
            [string]$app_id,
            [string]$organization,
            [string]$certificate,
            [SecureString]$password
    )
    {
        $this.url = $url
        try
        {
            $ByteArray = [System.Convert]::FromBase64String($certificate)
        }
        catch
        {
            throw "Could not decode the certificate. Try to re-enter it"
        }
        $this.certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($ByteArray, $password)

        $this.organization = $organization
        $this.app_id = $app_id
    }
    CreateSession()
    {
        $cmd_params = @{
            "AppID" = $this.app_id
            "Organization" = $this.organization
            "Certificate" = $this.certificate
        }
        Connect-ExchangeOnline @cmd_params -ShowBanner:$false -CommandName New-TenantAllowBlockListItems,Get-TenantAllowBlockListItems,Remove-TenantAllowBlockListItems -WarningAction:SilentlyContinue | Out-Null
    }
    DisconnectSession()
    {
        Disconnect-ExchangeOnline -Confirm:$false -WarningAction:SilentlyContinue 6>$null | Out-Null
    }
    [PSObject]
    GetEXOCASMailbox(
            [string]$identity,
            [string]$organizational_unit,
            [string]$primary_smtp_address,
            [string]$user_principal_name,
            [int]$limit
    )
    {
        $cmd_params = @{ }
        if ($identity)
        {
            $cmd_params.Identity = $identity
        }
        if ($organizational_unit)
        {
            $cmd_params.OrganizationalUnit = $organizational_unit
        }
        if ($primary_smtp_address)
        {
            $cmd_params.PrimarySmtpAddress = $primary_smtp_address
        }
        if ($user_principal_name)
        {
            $cmd_params.UserPrincipalName = $user_principal_name
        }
        $this.CreateSession()
        if ($limit -gt 0)
        {
            $results = Get-EXOCASMailbox @cmd_params -ResultSize $limit
        }
        else
        {
            $results = Get-EXOCASMailbox @cmd_params -ResultSize Unlimited
        }
        $this.DisconnectSession()
        return $results

        <#
        .DESCRIPTION
        This cmdlet returns a variety of client access settings for one or more mailboxes.
        These settings include options for Outlook on the web, Exchange ActiveSync, POP3, and IMAP4.
        This cmdlet is available only in the Exchange Online PowerShell V2 module.

        .PARAMETER identity
        The Identity parameter specifies the mailbox you want to view.
        For the best performance, we recommend using the following values:
            * User ID or user principal name (UPN)
            * GUID

        Otherwise, you can use any value that uniquely identifies the mailbox. For example:
            * Name
            * Alias
            * Distinguished name (DN)
            * Domain\Username
            * Email address
            * LegacyExchangeDN
            * SamAccountName

        .PARAMETER organizational_unit
        The OrganizationalUnit parameter filters the results based on the object's location in Active Directory.

        .PARAMETER primary_smtp_address
        The PrimarySmtpAddress identifies the mailbox that you want to view by primary SMTP email address (for example, navin@contoso.onmicrosoft.com).
        Can't be used with user_principal_name.

        .PARAMETER user_principal_name
        The UserPrincipalName parameter identifies the mailbox that you want to view by UPN (for example, navin@contoso.onmicrosoft.com).
        Can't be used with primary_smtp_address.

        .EXAMPLE
        GetEXOCasMailbox("1254y894-feae-9yn7-a3e1-f2483a154tft")

        .OUTPUTS
        PSObject - Raw response

        .LINK
        https://docs.microsoft.com/en-us/powershell/module/exchange/get-exocasmailbox?view=exchange-ps
        #>
    }

    [PSObject]
    GetEXOMailbox(
            [string]$identity,
            [string]$property_sets,
            [int]$limit
    )
    {
        $cmd_params = @{ }
        if ($identity)
        {
            $cmd_params.Identity = $identity
        }
        if ($property_sets)
        {
            $cmd_params.PropertySets = $property_sets
        }
        $this.CreateSession()
        if ($limit -gt 0)
        {
            $results = Get-EXOMailbox @cmd_params -ResultSize $limit
        }
        else
        {
            $results = Get-EXOMailbox @cmd_params -ResultSize Unlimited
        }
        $this.DisconnectSession()
        return $results
        <#
        .DESCRIPTION
        Use the Get-EXOMailbox cmdlet to view mailbox objects and attributes,
        populate property pages, or supply mailbox information to other tasks.
        This cmdlet is available only in the Exchange Online PowerShell V2 module

        .PARAMETER identity
        The Identity parameter specifies the mailbox you want to view.
        For the best performance, we recommend using the following values:
            * User ID or user principal name (UPN)
            * GUID

        Otherwise, you can use any value that uniquely identifies the mailbox. For example:
            * Name
            * Alias
            * Distinguished name (DN)
            * Domain\Username
            * Email address
            * LegacyExchangeDN
            * SamAccountName

        .EXAMPLE
        GetEXOMailbox("1254y894-feae-9yn7-a3e1-f2483a154tft")

        .OUTPUTS
        PSObject - Raw response

        .LINK
        https://docs.microsoft.com/en-us/powershell/module/exchange/get-exomailbox?view=exchange-ps
        #>
    }

    [PSObject]
    GetEXOMailboxPermission(
            [string]$identity
    )
    {
        # Import and Execute command
        $cmd_params = @{ }
        if ($identity)
        {
            $cmd_params.Identity = $identity
        }
        $this.CreateSession()
        $results = Get-EXOMailboxPermission @cmd_params
        $this.DisconnectSession()
        return $results

        <#
        .DESCRIPTION
        View information about SendAs permissions that are configured for users.
        This command is available only in the Exchange Online PowerShell V2 module.

        .PARAMETER identity
        The Identity parameter the user that you want to view. You can use any value that uniquely identifies the user

        .EXAMPLE
        GetEXOMailboxPermission("1254y894-feae-9yn7-a3e1-f2483a154tft")

        .OUTPUTS
        PSObject - Raw response

        .LINK
        https://docs.microsoft.com/en-us/powershell/module/exchange/get-exomailboxpermission?view=exchange-ps
        #>
    }
    [PSObject]
    GetEXORecipientPermission(
            [string]$identity,
            [int]$limit
    )
    {
        $cmd_params = @{ }
        if ($identity)
        {
            $cmd_params.Identity = $identity
        }
        $this.CreateSession()
        if ($limit -gt 0)
        {
            if ($identity)
            {
                $results = Get-EXORecipientPermission -Identity $identity -ResultSize $limit
            }
            else
            {
                $results = Get-EXORecipientPermission -ResultSize $limit
            }
        }
        else
        {
            if ($identity)
            {
                $results = Get-EXORecipientPermission -Identity $identity -ResultSize Unlimited
            }
            else
            {
                $results = Get-EXORecipientPermission -ResultSize Unlimited
            }
        }
        $this.DisconnectSession()
        return $results
        <#
        .DESCRIPTION
        Use the Get-EXORecipientPermission cmdlet to view information about SendAs permissions that are
        configured for users in a cloud-based organization.
        This command is available only in the Exchange Online PowerShell V2 module

        .PARAMETER identity
        The Identity parameter specifies the mailbox you want to view.
        For the best performance, we recommend using the following values:
            * User ID or user principal name (UPN)
            * GUID

        Otherwise, you can use any value that uniquely identifies the mailbox. For example:
            * Name
            * Alias
            * Distinguished name (DN)
            * Domain\Username
            * Email address
            * LegacyExchangeDN
            * SamAccountName
        #>
    }
    [PSObject]
    GetEXORecipient(
            [string]$identity,
            [int]$limit
    )
    {
        $cmd_params = @{ Properties="Guid" }
        if ($identity)
        {
            $cmd_params.Identity = $identity
        }
        $this.CreateSession()
        if ($limit -gt 0)
        {
            $results = Get-EXORecipient @cmd_params -ResultSize $limit
        }
        else
        {
            $results = Get-EXORecipient @cmd_params -ResultSize Unlimited
        }
        $this.DisconnectSession()
        return $results
        <#
            .DESCRIPTION
            Use the Get-ExORecipient cmdlet to view existing recipient objects in your organization.
            This cmdlet returns all mail-enabled objects (for example,
            mailboxes, mail users, mail contacts, and distribution groups).

            #>
    }

    [PSObject]
    EXONewTenantAllowBlockList(
            [string]$entries,
            [string]$list_type,
            [string]$list_subtype,
            [string]$action,
            [string]$notes,
            [bool]$no_expiration,
            [string]$expiration_date
    )
    {
        $cmd_params = @{ }
        $entries_array = @()
        if ($entries.Contains(','))
        {
            $entries_array = $entries -split ','
        }
        if ($entries -and -not $entries_array)
        {
            $entries_array += $entries
            $cmd_params.Entries = $entries_array
        }
        else
        {
            $cmd_params.Entries = $entries_array
        }
        if ($list_type)
        {
            $cmd_params.ListType = $list_type
        }
        if ($list_subtype)
        {
            $cmd_params.ListSubType = $list_subtype
        }
        if ($notes)
        {
            $cmd_params.Notes = $notes
        }
        if ($no_expiration)
        {
            $cmd_params.NoExpiration = $null
        }
        if ($expiration_date)
        {
            $cmd_params.ExpirationDate = $expiration_date
        }
        if ($action -eq "Block")
        {
            $cmd_params.Block = $null
        }
        if ($action -eq "Allow")
        {
            $cmd_params.Allow = $null
        }
        $this.CreateSession()
        $results = New-TenantAllowBlockListItems @cmd_params
        $this.DisconnectSession()
        return $results
        <#
            .DESCRIPTION
            Use the New-TenantAllowBlockListItems cmdlet to add new entries to the Tenant Allow/Block Lists for your organization.
            This cmdlet returns all new entries created, details about them, and their status

        #>
    }

    [PSObject]
    EXORemoveTenantAllowBlockList(
            [string]$entries,
            [string]$ids,
            [string]$list_type,
            [string]$list_subtype
    )
    {
        $cmd_params = @{ }
        $entries_array = @()
        $ids_array = @()
        if ($entries.Contains(','))
        {
            $entries_array = $entries -split ','
        }
        if ($entries -and -not $entries_array)
        {
            $entries_array += $entries
            $cmd_params.Entries = $entries_array
        }
        elseif ($entries_array)
        {
            $cmd_params.Entries = $entries_array
        }
        if ($ids -and $ids.Contains(','))
        {
            $ids_array = $ids -split ','
        }
        if ($ids -and -not $ids_array)
        {
            $ids_array += $ids
            $cmd_params.Ids = $ids_array
        }
        elseif ($ids_array)
        {
            $cmd_params.Ids = $ids_array
        }
        if ($list_type)
        {
            $cmd_params.ListType = $list_type
        }
        if ($list_subtype)
        {
            $cmd_params.ListSubType = $list_subtype
        }
        $this.CreateSession()
        $results = Remove-TenantAllowBlockListItems @cmd_params
        $this.DisconnectSession()
        return $results
        <#
            .DESCRIPTION
            Use the New-TenantAllowBlockListItems cmdlet to add new entries to the Tenant Allow/Block Lists for your organization.
            This cmdlet returns all new entries created, details about them, and their status

        #>
    }

    [PSObject]
    EXOGetTenantAllowBlockList(
            [string]$entry,
            [string]$list_type,
            [string]$list_subtype,
            [string]$action,
            [bool]$no_expiration,
            [string]$expiration_date
    )
    {
        $cmd_params = @{ }
        if ($entry)
        {
            $cmd_params.Entry = $entry
        }
        if ($list_type)
        {
            $cmd_params.ListType = $list_type
        }
        if ($list_subtype)
        {
            $cmd_params.ListSubType = $list_subtype
        }
        if ($no_expiration)
        {
            $cmd_params.NoExpiration = $null
        }
        if ($expiration_date)
        {
            $cmd_params.ExpirationDate = $expiration_date
        }
        if ($action -eq "Block")
        {
            $cmd_params.Block = $null
        }
        if ($action -eq "Allow")
        {
            $cmd_params.Allow = $null
        }
        $this.CreateSession()
        $results = Get-TenantAllowBlockListItems @cmd_params
        $this.DisconnectSession()
        return $results
        <#
            .DESCRIPTION
            Use the Get-TenantAllowBlockListItems cmdlet to retrieve current entries in the Tenant Allow/Block Lists for your organization.
            This cmdlet returns current entries and details about them.

        #>
    }
}

function GetEXORecipientCommand
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)][ExchangeOnlinePowershellV2Client]$client,
        [hashtable]$kwargs
    )
    $identity = $kwargs.identity
    $limit = $kwargs.limit -as [int]
    $raw_response = $client.GetEXORecipient($identity, $limit)
    $human_readable = TableToMarkdown $raw_response "Results of $command"
    $entry_context = @{ "$script:INTEGRATION_ENTRY_CONTEXT.Recipient(obj.Guid === val.Guid)" = $raw_response }
    Write-Output $human_readable, $entry_context, $raw_response
}

function GetEXORecipientPermissionCommand
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)][ExchangeOnlinePowershellV2Client]$client,
        [hashtable]$kwargs
    )
    $identity = $kwargs.identity
    $limit = $kwargs.limit -as [int]
    $raw_response = $client.GetEXORecipientPermission($identity, $limit)
    $human_readable = TableToMarkdown $raw_response "Results of $command"
    $entry_context = @{ "$script:INTEGRATION_ENTRY_CONTEXT.RecipientPermission(obj.Identity === val.Identity)" = $raw_response }
    Write-Output $human_readable, $entry_context, $raw_response
}
function GetEXOMailBoxPermissionCommand
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)][ExchangeOnlinePowershellV2Client]$client,
        [hashtable]$kwargs
    )
    $identity = $kwargs.identity
    $raw_response = $client.GetEXOMailBoxPermission($identity)
    $human_readable = TableToMarkdown $raw_response "Results of $command"
    $entry_context = @{
        "$script:INTEGRATION_ENTRY_CONTEXT.MailboxPermission(obj.Identity === val.Identity)" = @{
            "Identity" = $identity
            "Permission" = $raw_response
        }
    }
    Write-Output $human_readable, $entry_context, $raw_response
}
function GetEXOMailBoxCommand
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)][ExchangeOnlinePowershellV2Client]$client,
        [hashtable]$kwargs
    )
    $identity = $kwargs.identity
    $limit = $kwargs.limit -as [int]
    $raw_response = $client.GetEXOMailBox($identity, $kwargs.property_sets, $limit)
    $human_readable = TableToMarkdown $raw_response "Results of $command"
    $entry_context = @{
        "$script:INTEGRATION_ENTRY_CONTEXT.Mailbox(obj.Guid === val.Guid)" = $raw_response }
    Write-Output $human_readable, $entry_context, $raw_response
}
function GetEXOCASMailboxCommand
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory)][ExchangeOnlinePowershellV2Client]$client,
        [hashtable]$kwargs
    )
    $identity = $kwargs.identity
    $organizational_unit = $kwargs.organizational_unit
    $primary_smtp_address = $kwargs.primary_smtp_address
    $user_principal_name = $kwargs.user_principal_name
    $limit = $kwargs.limit -as [int]
    $raw_response = $client.GetEXOCASMailbox(
            $identity, $organizational_unit, $primary_smtp_address, $user_principal_name, $limit
    )
    $human_readable = TableToMarkdown $raw_response "Results of $command"
    $entry_context = @{ "$script:INTEGRATION_ENTRY_CONTEXT.CASMailbox(obj.Guid === val.Guid)" = $raw_response }
    Write-Output $human_readable, $entry_context, $raw_response
}

function EXONewTenantAllowBlockListCommand
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory)][ExchangeOnlinePowershellV2Client]$client,
        [hashtable]$kwargs
    )
    $entries = $kwargs.entries
    $list_type = $kwargs.list_type
    $list_subtype = $kwargs.list_subtype
    $action = $kwargs.action
    $notes = $kwargs.notes
    $no_expiration = if ($kwargs.no_expiration -eq "true") { $true } else { $false }
    $expiration_date = $kwargs.expiration_date
    $raw_response = $client.EXONewTenantAllowBlockList(
        $entries, $list_type, $list_subtype, $action, $notes, $no_expiration, $expiration_date
    )
    $human_readable = TableToMarkdown $raw_response "Results of $command"
    $entry_context = @{ "$script:INTEGRATION_ENTRY_CONTEXT.NewTenantBlocks" = $raw_response }
    Write-Output $human_readable, $entry_context, $raw_response

}

function EXOGetTenantAllowBlockListCommand
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory)][ExchangeOnlinePowershellV2Client]$client,
        [hashtable]$kwargs
    )
    $entry = $kwargs.entry
    $list_type = $kwargs.list_type
    $list_subtype = $kwargs.list_subtype
    $action = $kwargs.action
    $no_expiration = if ($kwargs.no_expiration -eq "true") { $true } else { $false }
    $expiration_date = $kwargs.expiration_date
    $raw_response = $client.EXOGetTenantAllowBlockList(
        $entry, $list_type, $list_subtype, $action, $no_expiration, $expiration_date
    )
    $human_readable = TableToMarkdown $raw_response "Results of $command"
    $entry_context = @{ "$script:INTEGRATION_ENTRY_CONTEXT.CurrentTenantBlocks" = $raw_response }
    Write-Output $human_readable, $entry_context, $raw_response
}

function EXOCountTenantAllowBlockListCommand
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory)][ExchangeOnlinePowershellV2Client]$client,
        [hashtable]$kwargs
    )
    $list_type = $kwargs.list_type
    $list_subtype = $kwargs.list_subtype
    $m = $client.EXOGetTenantAllowBlockList($null, $list_type, $list_subtype, $null, $null, $null) | Measure-Object
    $raw_response = [PSCustomObject]@{
        ListType = $list_type
        ListSubType = $list_subtype
        Count = $m.Count
    }
    $human_readable = TableToMarkdown $raw_response "Results of $command"
    $entry_context = @{ "$script:INTEGRATION_ENTRY_CONTEXT.CurrentListCount" = $raw_response }
    Write-Output $human_readable, $entry_context, $raw_response

}

function EXORemoveTenantAllowBlockListCommand
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory)][ExchangeOnlinePowershellV2Client]$client,
        [hashtable]$kwargs
    )
    $entries = $kwargs.entries
    $ids = $kwargs.ids
    $list_type = $kwargs.list_type
    $list_subtype = $kwargs.list_subtype
    if ($entries -and $ids)
    {
        ReturnError "Error: Please provide either entries by value OR IDs, not both."
    }
    $raw_response = $client.EXORemoveTenantAllowBlockList(
        $entries, $ids, $list_type, $list_subtype
    )
    $human_readable = TableToMarkdown $raw_response "Results of $command"
    $entry_context = @{ "$script:INTEGRATION_ENTRY_CONTEXT.RemovedTenantBlocks" = $raw_response }
    Write-Output $human_readable, $entry_context, $raw_response

}

function TestModuleCommand($client)
{
    try
    {
        $client.CreateSession()
        $demisto.results("ok")
    }
    finally
    {
        $client.DisconnectSession()
    }

}
function Main
{
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
    param()
    $command = $demisto.GetCommand()
    $command_arguments = $demisto.Args()
    $integration_params = [Hashtable] $demisto.Params()

    if ($integration_params.password.password)
    {
        $password = ConvertTo-SecureString $integration_params.password.password -AsPlainText -Force
    }
    else
    {
        $password = $null
    }

    $exo_client = [ExchangeOnlinePowershellV2Client]::new(
            $integration_params.url,
            $integration_params.app_id,
            $integration_params.organization,
            $integration_params.certificate.password,
            $password
    )
    try
    {
        # Executing command
        $Demisto.Debug("Command being called is $Command")
        switch ($command)
        {
            "test-module" {
                ($human_readable, $entry_context, $raw_response) = TestModuleCommand $exo_client
            }
            "$script:COMMAND_PREFIX-cas-mailbox-list" {
                ($human_readable, $entry_context, $raw_response) = GetEXOCASMailboxCommand $exo_client $command_arguments
            }
            "$script:COMMAND_PREFIX-mailbox-list" {
                ($human_readable, $entry_context, $raw_response) = GetEXOMailBoxCommand $exo_client $command_arguments
            }
            "$script:COMMAND_PREFIX-mailbox-permission-list" {
                ($human_readable, $entry_context, $raw_response) = GetEXOMailBoxPermissionCommand $exo_client $command_arguments
            }
            "$script:COMMAND_PREFIX-recipient-permission-list" {
                ($human_readable, $entry_context, $raw_response) = GetEXORecipientPermissionCommand $exo_client $command_arguments
            }
            "$script:COMMAND_PREFIX-recipient-list" {
                ($human_readable, $entry_context, $raw_response) = GetEXORecipientCommand $exo_client $command_arguments
            }
            "$script:COMMAND_PREFIX-new-tenant-allow-block-list-items" {
                ($human_readable, $entry_context, $raw_response) = EXONewTenantAllowBlockListCommand $exo_client $command_arguments
            }
            "$script:COMMAND_PREFIX-get-tenant-allow-block-list-items" {
                ($human_readable, $entry_context, $raw_response) = EXOGetTenantAllowBlockListCommand $exo_client $command_arguments
            }
            "$script:COMMAND_PREFIX-get-tenant-allow-block-list-count" {
                ($human_readable, $entry_context, $raw_response) = EXOCountTenantAllowBlockListCommand $exo_client $command_arguments
            }
            "$script:COMMAND_PREFIX-remove-tenant-allow-block-list-items" {
                ($human_readable, $entry_context, $raw_response) = EXORemoveTenantAllowBlockListCommand $exo_client $command_arguments
            }
            default {
                ReturnError "Could not recognize $command"
            }
        }
        # Return results to Demisto Server
        ReturnOutputs $human_readable $entry_context $raw_response | Out-Null
    }
    catch
    {
        $Demisto.debug(
                "Integration: $script:INTEGRATION_NAME
        Command: $command
        Arguments: $( $command_arguments | ConvertTo-Json )
        Error: $( $_.Exception.Message )"
        )
        if ($command -ne "test-module")
        {
            ReturnError "Error:
            Integration: $script:INTEGRATION_NAME
            Command: $command
            Arguments: $( $command_arguments | ConvertTo-Json )
            Error: $( $_.Exception )"
        }
        else
        {
            ReturnError $_.Exception.Message
        }
    }
    finally
    {
        # Always disconnect the session, even if no sessions available.
        $exo_client.DisconnectSession()
    }
}

# Execute Main when not in Tests
if ($MyInvocation.ScriptName -notlike "*.tests.ps1" -AND -NOT$Test)
{
    Main
}