Generate Office 365 PAC Files with PowerShell

If you have a proxy server in your environment and are using (or thinking about using) Office 365 then you will hit some pain barriers. As awesome as Office 365 is, she just isn’t a fan of proxies.

We used to be left to our own initiative, creating complex proxy bypass rules and guessing which URLs we had to exclude. This process is compounded if you also maintain a strict CIDR range on your Firewall for Office 365 endpoints.

Introducing Get-PacFile

This script will access updated information to create a PAC file to prioritize Microsoft 365 Urls for better access to the service. This script will allow you to create different types of files depending on how traffic needs to be prioritized.

Microsoft Gallery Comment

Head over to the Gallery to view the script

Go ahead and install it by using the command:-


You will be prompted to also install the “NuGet Provider”. Go ahead.


Below is a list of parameters you can pass to the script to customize the generated PAC.

Type – The type of the proxy PAC file that you want to generate. 

  • 1 – Send Optimize endpoint traffic direct and everything else to the proxy server. 
  • 2 – Send Optimize and Allow endpoint traffic direct and everything else to the proxy server. This type can also be used to send all supported ExpressRoute for Office 365 traffic to ExpressRoute network segments and everything else to the proxy server. 

ClientRequestID – This is required and is a GUID passed to the web service that represents the client machine making the call. 


Instance – The Office 365 service instance which defaults to Worldwide. Also passed to the web service. 

  • Worldwide
  • Germany
  • China
  • USGovDoD
  • USGovGCCHigh

Tenant Name – Your Office 365 tenant name. Passed to the web service and used as a replaceable parameter in some Office 365 URLs.

DefaultProxySettings – Your Proxy Server and Port preceded with the word “PROXY”


DirectProxySettings  – The direct proxy settings for priority traffic. 

ServiceAreas – What Services do you want defined in the PAC

  • Exchange – Exchange Online and Exchange Online Protection 
  • SharePoint – SharePoint Online and OneDrive for Business 
  • Skype – Skype for Business and Microsoft Teams 
  • Common – Office 365 Pro Plus, Office Online, Azure AD and other common network endpoints 

LowerCase – Flag this to include lowercase transformation into the PAC file for the host name matching.



.\Get-PacFile.ps1 -ClientRequestId b10c5ed1-bad1-445f-b386-b919946339a7 -DefaultProxySettings “PROXY” > type1.pac 


.\Get-PacFile.ps1 -ClientRequestId b10c5ed1-bad1-445f-b386-b919946339a7 -Instance China -Type 2 -DefaultProxySettings “PROXY” > type2.pac 


.\Get-PacFile.ps1 -ClientRequestId b10c5ed1-bad1-445f-b386-b919946339a7 -Instance WorldWide -Lowercase -TenantName tenantName -ServiceAreas Sharepoint,Skyp

Examples given in the script

Don’t forget to export the PAC to a file using >file.txt

Example of PAC Generated
“Tenant” parameter passed and highlighted in the generated PAC file

Leave a Reply to Robert Larsson Cancel reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.


This site uses Akismet to reduce spam. Learn how your comment data is processed.

8 thoughts on “Generate Office 365 PAC Files with PowerShell”