Run Outlook as a different user

Ask your Windows 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.
Locked
User avatar
JohnTitor
Posts: 153
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Fri Nov 17, 2017 8:49 pm

Run Outlook as a different user

Post by JohnTitor »

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.  
  3. $timestamp = Get-Date
  4.  
  5.     $ol = New-Object -comObject Outlook.Application
  6.  
  7.    
  8.  
  9.     #Create the new email
  10.  
  11.     $mail = $ol.CreateItem(0)
  12.  
  13.    
  14.  
  15.     $mail.To = 'me@asdf.com'
  16.  
  17.    
  18.  
  19.     #Optional, set the subject
  20.  
  21.     $mail.Subject = "$($labelBanner.Text)"
  22.  
  23.    
  24.  
  25.     #Optional, set the body
  26.  
  27.     $mail.Body = "Username:               $env:USERNAME
  28.  
  29.        Computername:     $($textboxcomputername.Text)
  30.  
  31.        Date of use:             $timestamp
  32.  
  33.        Comments:              
  34.  
  35. "
  36.  
  37.    
  38.  
  39.     #Get the new email object
  40.  
  41.     $inspector = $mail.GetInspector
  42.  
  43.    
  44.  
  45.     #Bring the message window to the front
  46.  
  47.     $inspector.Display()
  48.  
  49.  

jvierra
Posts: 14370
Joined: Tue May 22, 2007 9:57 am
Contact:

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
JohnTitor
Posts: 153
Joined: Fri Nov 17, 2017 8:49 pm

Re: Run Outlook as a different user

Post by JohnTitor »

I was able to get around it by using send-mailmessage and a few other tricks

Locked