Run Outlook as a different user

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Run Outlook as a different user

Post by apowershelluser »

We have two IDs. Our primary ID and our Admin ID

I have a form that I have to launch as my admin ID

Is there a way to run outlook as my primary ID using an button event?
  1.  
  2. $timestamp = Get-Date
  3.     $ol = New-Object -comObject Outlook.Application
  4.    
  5.     #Create the new email
  6.     $mail = $ol.CreateItem(0)
  7.    
  8.     $mail.To = 'me@asdf.com'
  9.    
  10.     #Optional, set the subject
  11.     $mail.Subject = "$($labelBanner.Text)"
  12.    
  13.     #Optional, set the body
  14.     $mail.Body = "Username:               $env:USERNAME
  15.        Computername:     $($textboxcomputername.Text)
  16.        Date of use:             $timestamp
  17.        Comments:              
  18. "
  19.    
  20.     #Get the new email object
  21.     $inspector = $mail.GetInspector
  22.    
  23.     #Bring the message window to the front
  24.     $inspector.Display()
  25.  
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Run Outlook as a different user

Post by jvierra »

No. To run as a different account might start Outlook but it would be inaccessible due to process isolation.
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Run Outlook as a different user

Post by apowershelluser »

I was able to get around it by using send-mailmessage and a few other tricks
This topic is 5 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked