PowerShell
Overview
The PowerShell connector enables your AI Colleagues to integrate with your organization's Microsoft 365 and Exchange environments, facilitating automated IT administration tasks, script execution, and mailbox management workflows.
PowerShell is a cross-platform task automation solution comprising a command-line shell and a configuration management framework. This connector can configure Microsoft Exchange use cases such as creating Distribution Lists, managing Shared Mailboxes, managing user access permissions, and executing custom automation scripts.
API Details
Leena AI integrates with PowerShell via Microsoft Graph REST APIs and remote PowerShell script execution.
Documentation link: https://learn.microsoft.com/en-us/graph/overview
Setup
The PowerShell connector uses OAuth 2.0 authentication with the Client Credentials grant type for server-to-server interactions.
Prerequisites
Before setting up the PowerShell connector, ensure you have:
- Administrator access to Microsoft Entra admin center (formerly Azure Active Directory)
- Access to create App Registrations in Microsoft Entra ID
- Permission to grant admin consent for API permissions
- Access to your Leena AI workspace with connector management permissions
Get credentials
Here is how to create an OAuth application in Microsoft Entra admin center:
- Sign in to the Microsoft Entra admin center (https://entra.microsoft.com)
- Navigate to App Registrations:
- Browse to Identity > Applications > App registrations
- Select New registration
- Register the Application:
- Enter a display Name for your application (e.g., "Leena AI PowerShell Connector")
- Select Accounts in this organizational directory only for supported account types
- Leave Redirect URI empty (not required for client credentials flow)
- Click Register
- Note the Application Credentials:
- Record the Application (client) ID from the Overview page
- Record the Directory (tenant) ID from the Overview page
- Create Client Secret:
- Navigate to Certificates & secrets
- Click New client secret
- Enter a description (e.g., "Leena AI Integration")
- Select an expiration period (recommended: 12 months or less)
- Click Add
- Copy the Value immediately (this is only shown once)
- Configure API Permissions:
- Navigate to API permissions
- Click Add a permission
- Select Microsoft Graph
- Select Application permissions
- Add the following permissions based on your use case:
- User.Read.All (for user management)
- Group.ReadWrite.All (for group and distribution list management)
- Mail.ReadWrite (for mailbox operations)
- Directory.Read.All (for directory queries)
- Click Add permissions
- Grant Admin Consent:
- Click Grant admin consent for [Your Tenant Name]
- Confirm by clicking Yes
- Verify all permissions show "Granted" status
Add connection
Here is how to add a connection on Leena AI:
- Log in to your Leena AI workspace
- Navigate to Settings > Integrations
- Search for "PowerShell" and select it from the list to add its new connector
- Start configuring the connector
- Auth Type: Select "Powershell" from the dropdown
- Settings: Add the following key-value pairs:
- clientId: Your Application (client) ID from Azure
- clientSecret: Your client secret value
- tenantId: Your Directory (tenant) ID
- Save the connection configuration
- Test the connection to verify credentials are working correctly
Actions
The following actions are supported for the PowerShell connector:
Execute PowerShell Script
Executes a predefined PowerShell script from the template library. The Agent can leverage the skill (workflow), which has been designed to run automation scripts for various Microsoft 365 and Exchange management tasks.
Note: This action uses a dynamic form system. When you select a PowerShell Script, the form fields change dynamically based on the selected script's configuration. Each script type has its own set of required and optional parameters.
Input Parameters
Here are the input parameters required to set up this action:
Step 1: Select Script (Mandatory)
| Name | Description |
|---|---|
| Powershell Script | Select the PowerShell script template to execute from the dropdown |
Step 2: Script-Specific Fields (Dynamic)
Once a script is selected, additional fields appear based on the script's configuration. Below are common script types and their respective fields:
Add User to Shared Mailbox
Grants a user access to a shared mailbox with specified permissions.
| Name | Type | Required | Description |
|---|---|---|---|
| Shared Mailbox | Select | Yes | The shared mailbox to grant access to |
| Users | Multi-Select | Yes | Users to add to the shared mailbox |
| Access Rights | Select | Yes | Permission level (FullAccess, SendAs, SendOnBehalf) |
{
"scriptType": "add_user_to_shared_mailbox",
"sharedMailboxEmail": "[email protected]",
"users": ["[email protected]", "[email protected]"],
"accessRights": "FullAccess"
}Remove User from Shared Mailbox
Revokes a user's access from a shared mailbox.
| Name | Type | Required | Description |
|---|---|---|---|
| Shared Mailbox | Select | Yes | The shared mailbox to revoke access from |
| Users | Multi-Select | Yes | Users to remove from the shared mailbox |
| Access Rights | Select | Yes | Permission level to revoke |
{
"scriptType": "remove_user_from_shared_mailbox",
"sharedMailboxEmail": "[email protected]",
"users": ["[email protected]"],
"accessRights": "FullAccess"
}List Shared Mailbox Members
Retrieves all members of a shared mailbox with their access levels.
| Name | Type | Required | Description |
|---|---|---|---|
| Shared Mailbox | Select | Yes | The shared mailbox to list members from |
| Access Type | Select | No | Filter by permission type (FullAccess, SendAs, etc.) |
{
"scriptType": "list_shared_mailbox_members",
"sharedMailboxEmail": "[email protected]",
"accessRights": "FullAccess"
}Create Shared Mailbox
Creates a new shared mailbox in the tenant.
| Name | Type | Required | Description |
|---|---|---|---|
| Shared Mailbox Name | Input | Yes | Display name for the new shared mailbox |
| Shared Mailbox Alias | Input | Yes | Email alias for the shared mailbox |
{
"scriptType": "create_shared_mailbox",
"sharedMailboxName": "Customer Support",
"sharedMailboxAlias": "support"
}Delete Shared Mailbox
Removes an existing shared mailbox from the tenant.
| Name | Type | Required | Description |
|---|---|---|---|
| Shared Mailbox | Select | Yes | The shared mailbox to delete |
{
"scriptType": "delete_shared_mailbox",
"sharedMailboxEmail": "[email protected]"
}Add User to Distribution Group
Adds users as members to a distribution group.
| Name | Type | Required | Description |
|---|---|---|---|
| Group | Select | Yes | The distribution group to add members to |
| Users | Multi-Select | Yes | Users to add to the group |
{
"scriptType": "add_user_to_group",
"groupId": "[email protected]",
"users": ["[email protected]"]
}Remove User from Distribution Group
Removes users from a distribution group.
| Name | Type | Required | Description |
|---|---|---|---|
| Group | Select | Yes | The distribution group to remove members from |
| Users | Multi-Select | Yes | Users to remove from the group |
{
"scriptType": "remove_user_from_group",
"groupId": "[email protected]",
"users": ["[email protected]"]
}List Mailbox
Retrieves all shared mailboxes in the tenant.
| Name | Type | Required | Description |
|---|---|---|---|
| Search String | Input | No | Filter mailboxes by name or email |
{
"scriptType": "list_mailbox",
"searchString": "support"
}Response
Upon successful execution, the action returns:
- Execution status (success or failure)
- Script output data (formatted as JSON if post-processing is configured)
- Error details (if execution failed)
Dynamic Data Sources (Async Hooks)
The PowerShell connector provides dynamic dropdowns that fetch real-time data from your Microsoft 365 tenant:
| Data Source | Description |
|---|---|
| Domains | Lists all registered domains in the tenant |
| Groups | Lists all distribution groups |
| Shared Mailbox | Lists all shared mailboxes |
| Users | Lists all users in the tenant |
| Users not guest | Lists internal users only (excludes guest accounts) |
| Users in group | Lists members of a specific group |
| Users not in group | Lists users who are not members of a specific group |
| Users in shared mailbox | Lists users with access to a specific shared mailbox |
| Users not in shared mailbox | Lists users without access to a specific shared mailbox |
| Users in shared mailbox basis access | Lists users with specific access rights to a shared mailbox |
| Users not in shared mailbox basis access | Lists users without specific access rights to a shared mailbox |
| Users in shared mailbox not guest basis access | Lists non-guest users with specific access to a shared mailbox |
Script Template Configuration
Administrators can create and manage custom PowerShell script templates through the Template Scripts platform. Each template defines its own form fields, making the connector highly extensible.
Template Schema
| Field | Type | Required | Description |
|---|---|---|---|
| Name | String | Yes | A human-readable display name for the script |
| Type | String | Yes | A unique string identifier for the script |
| Script | String | Yes | The PowerShell script body with Lodash template variables |
| Form | IFormConfig[] | No | An array defining the UI form components to collect input variables |
| Post Execution Script | String | No | JavaScript code to transform the script output into structured JSON |
| Bot ID | String | No | If specified, script is available only to this bot; otherwise global |
Sample Script Template
{
"name": "Add User to Shared Mailbox",
"type": "add_user_to_shared_mailbox",
"script": "Add-MailboxPermission -Identity '<%= sharedMailboxEmail %>' -User '<%= users[0] %>' -AccessRights '<%= accessRights %>'",
"form": [
{
"name": "sharedMailboxEmail",
"type": "SELECT",
"label": "Shared Mailbox",
"required": true,
"asyncHook": "shared-mailbox-all"
},
{
"name": "users",
"type": "MULTI_SELECT",
"label": "Users to Add",
"required": true,
"asyncHook": "users-not-in-shared-mailbox-basis-access"
},
{
"name": "accessRights",
"type": "SELECT",
"label": "Access Rights",
"required": true,
"props": {
"options": [
{"label": "Full Access", "value": "FullAccess"},
{"label": "Send As", "value": "SendAs"},
{"label": "Send on Behalf", "value": "SendOnBehalf"}
]
}
}
],
"postExecutionScript": "commandOutput = JSON.parse(commandOutput); commandOutput;"
}Template Variables
Script templates support Lodash template syntax for dynamic value injection:
| Syntax | Description |
|---|---|
<%= variableName %> | Inserts the value of the variable |
<%= users[0] %> | Accesses array elements |
<%= _.join(users, ',') %> | Uses Lodash functions for complex transformations |
Form Field Types
| Type | Description |
|---|---|
| INPUT | Single-line text input |
| SELECT | Dropdown selection (single value) |
| MULTI_SELECT | Dropdown selection (multiple values) |
| TEXTAREA | Multi-line text input |
| FIELD_ARRAY | Dynamic list of key-value pairs |
Updated 1 day ago
