Outlook "Work Offline" Mode

 Since I've mainly only found this in terms of a VB Script. I'm going to post my version of it in PowerShell for anyone who is looking for something similar. 


1:  #Check if Outlook is online or offline mode  
2:  $Outlook = New-Object -ComObject Outlook.Application;  
3:  $State = if ($outlook.session.offline) {"Outlook has been set to work offline mode." } else { "Healthy - Outlook is in online mode." };  
4:  $State;  
5:    
6:    
7:  #Toggle Outlook to online mode  
8:  Try {  
9:    $Outlook = New-Object -ComObject Outlook.Application  
10:    $State = "Toggle"  
11:    if ($outlook.session.offline)   
12:    {  
13:    $Outlook.ActiveExplorer().CommandBars.ExecuteMSO("ToggleOnline")  
14:    }  
15:    else   
16:    {   
17:    "Outlook already in online mode."  
18:    }  
19:    ConvertTo-Json($State)  
20:    }   
21:    Catch  
22:    {  
23:    If ($_.Exception.Message.Contains("Class not registered"))  
24:    {  
25:    ConvertTo-Json("No Outlook Registered")  
26:    }  
27:    Else  
28:    {  
29:     ConvertTo-Json("Unknown Outcome")  
30:    }  
31:    }  


If you happen to use 1E Tachyon these scripts are in the Microsoft Outlook Pack on Tachyon Exchange

Comments

Popular posts from this blog

Stuck @ "Waiting for user logon"

Intune Hybrid - NDES Cert Issue

Triggering a software update install via Powershell