Read Mail via Powershell

Copper Contributor

I want to develop an automatic task for creating an LDAP account.

 

i tried in developer.microsoft.com is ok return the body  

https://graph.microsoft.com/v1.0/me/messages?$search="subject:\"New+Joiners\"" 

 but i in the Powershell

$ApplicationId = "ID"
$SecuredPassword = "SecuredPassword"
$tenantID = "tenantID "
$userId = "email address removed for privacy reasons"


$SecuredPasswordPassword = ConvertTo-SecureString `
-String $SecuredPassword -AsPlainText -Force

$ClientSecretCredential = New-Object `
-TypeName System.Management.Automation.PSCredential `
-ArgumentList $ApplicationId, $SecuredPasswordPassword

Connect-MgGraph -TenantId $tenantID -ClientSecretCredential $ClientSecretCredential
Import-Module Microsoft.Graph.Mail

Get-MgUserMessage -UserId $userId -Search '"subject:\"New Onboarding\"'

 

 

i got an error 

Welcome to Microsoft Graph!

Connected via apponly access using d930dffa-0d53-459d-a649-016cd65d46ec
Readme: https://aka.ms/graph/sdk/powershell
SDK Docs: https://aka.ms/graph/sdk/powershell/docs
API Docs: https://aka.ms/graph/docs

NOTE: You can use the -NoWelcome parameter to suppress this message.

Get-MgUserMessage : One or more errors occurred.
At C:\Users\peter.cheungts\Documents\Untitled3_1.ps1:17 char:1
+ Get-MgUserMessage -UserId $userId -Search '"subject:\"New Onboarding\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-MgUserMessage_List], AggregateException
    + FullyQualifiedErrorId : System.AggregateException,Microsoft.Graph.PowerShell.Cmdlets.GetMgUserMessage_List

 

 

 

May i know how to fix it?

0 Replies