I have a powershell script that opens an outlook mail object and attaches a file to it. Whenever it runs Outlook shows a "suspicious activity" dialog where the user has to click on "Allow" or "Deny". I know that this can be turned off in the trust center, but since i'm not an admin this is not possible.
My code looks like this:
$Outlook = [Runtime.Interopservices.Marshal]::GetActiveObject('Outlook.Application')
$Mail = $Outlook.CreateItem(0)
$Mail.Attachments.Add($TmpFile)
$Mail.Display()
I've read the microsoft docs on this issue and ported the relevant code https://learn.microsoft.com/en-us/office/vba/outlook/how-to/security/obtain-and-log-on-to-an-instance-of-outlook (see line 1 of my code) but it doesn't seem to work. Is there a way through code to prevent the dialog from showing, through for example signing in, or am i out of luck?