Site icon JD Bots

How to Connect to Native Outlook using PowerShell?

To connect to native Outlook Application using PowerShell.

Outlook Application should be already logged in.

Find the PowerShell Code below:

There are two ways :

Connect to running Outlook application object which is already active. Then use below code.

Add-Type -assembly "Microsoft.Office.Interop.Outlook"
Add-Type -assembly "System.Runtime.Interopservices"
$Outlook = [Runtime.Interopservices.Marshal]::GetActiveObject('Outlook.Application')
$Namespace = $Outlook.GetNameSpace("MAPI")
$EmailFolderName = "FolderName"
$EmailFolder = $Namespace.Folders.Items(1).Folders.Item($EmailFolderName).Items

To create a new Outlook object:

$Outlook = New-Object -comobject Outlook.Application
$Namespace = $Outlook.GetNameSpace("MAPI")
$EmailFolderName = "FolderName"
$EmailFolder = $Namespace.Folders.Items(1).Folders.Item($EmailFolderName).Items

Thank you All!!! Hope you find this useful.


Exit mobile version