Share via

Export Quarantine using a script

Marc 631 Reputation points
2021-12-27T11:16:36.887+00:00

I am trying to create a script that export the quarantena of the list of the day when it is runned.

To make it automatic I have to enter the user's password when connecting to the tenant (how??):

Connect-IPPSSession -UserPrincipalName ******@contoso.com -ConnectionUri https://ps.protection.outlook.com/powershell-liveid/

and include the script below which works but capture only a very low number of data.

$today=(get-date)
$keydate=$today.Date.AddDays(-1)
Get-QuarantineMessage | Where-Object {($_.receivedtime -ge $keydate) -and ($_.ReleaseStatus -ne ‘RELEASED’)} | Export-Csv -Path C:\quarantined.csv
Exchange | Exchange Server | Management
Exchange | Exchange Server | Management

The administration and maintenance of Microsoft Exchange Server to ensure secure, reliable, and efficient email and collaboration services across an organization.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

Answer accepted by question author

Rich Matheisen 48,116 Reputation points
2021-12-27T16:09:46.847+00:00

Assuming(!) that the account doesn't use MFA:

Step 1:

$cred = Get-Credential
$cred | Export-Clixml -Path c:\junk\mycredential.cred

Step 2:

$cred = Import-Clixml -Path c:\junk\mycredential.cred
Connect-IPPSSession -Credential $cred -ConnectionUri https://ps.protection.outlook.com/powershell-liveid/

Was this answer helpful?

0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Marc 631 Reputation points
    2021-12-27T16:26:07.95+00:00

    Thank you it worked.

    Do you have any suggestion regarding the quarantine list?

    Was this answer helpful?


  2. Marc 631 Reputation points
    2021-12-27T15:57:36.483+00:00

    Hi RichMatheisen-8856,

    could you please help me to find a way to include user and password (even plan/visible) inside the script in orther to make it works without human interaction?

    Do you know why the command "Get-QuarantineMessage | Where-Object {($_.receivedtime -ge $keydate)" doesn't work properly ? It is giving a low list of emails.

    Was this answer helpful?

    0 comments No comments

  3. Rich Matheisen 48,116 Reputation points
    2021-12-27T15:31:33.993+00:00

    The Connect-IPPSSession takes a credential as a parameter. You can create the credential and save it to a file independently and use the file to recreate the credential in your script. The easiest way is to save the credential as an XML file.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.