Living a SharePoint life

Tuesday, January 17, 2017

Connect to Office365 via Office PnP behind a proxy

How do you connect to your SharePoint Office365 tenant with the PowerShell if you are locked behind a proxy? This hint will probably work for all kind of PowerShell scripts, not only for Office PnP. I tried this with the Microsoft SharePoint Online extensions as well and it worked.

So my problem was, the company I was working for, had a proxy which could not be bypassed. The proxy settings have been set by a GPO and the network settings where fine so far. However the proxy used user authentication to access the internet. Now if I want to use the SharePoint Online tools, I must authenticate my PowerShell session at the proxy so the tools can access the internet too.

The trick to get your PowerShell connected is quite simple. You only need to enter the following line:

[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials

Now you should be able to connect to Office365 SharePoint without problems. If you don't want to enter this line every time you open a new PowerShell, you could add it to your PowerShell profile.

then add this to the profile file:

#Set user default credentials for any webrequest
"Setting the users default credentials for WebRequests..." | Write-Host -ForegroundColor White
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials


  1. Trying to connect to may site collection ( SP2016) but through a proxy(

    $cred = [System.Net.CredentialCache]::DefaultCredentials
    [System.Net.WebRequest]::DefaultWebProxy.Credentials = $cred
    Connect-PnPOnline -Url https://xxx -UseWebLogin
    he problem is no connection was made:

    Get-PnPWeb or Get-PnPSite is null

    Get-PnPSite : Cannot contact site at the specified URL https://xxx/. Au caractère Ligne:1 : 1 + Get-PnPSite + ~~~~~~~~~~~ + CategoryInfo : WriteError: (:) [Get-PnPSite], ClientRequestException + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Site.GetSite

    1. As long as you havn't connected to the site thru Connect-PnPOnline, every other PnP cmdlet will fail and raise an exception.
      The PowerShell line [System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials will set the context of the user running the PowerShell to be used for any kind of http connection estabished thru System.Net.Webrequest. Possible problems may be the user isn't allowd to login to the proxy, or the proxy does deep packet inspections and SSL termination to block unauthorized traffic.

  2. I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit. Office video intercom installation

  3. This short article posted only at the web site is truly good.

  4. You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers. 1337x

  5. Thanks to innovations in Internet technology, it is a lot easier (and often more profitable) to utilize the services of a remote workforce to handle a business's many tasks mindmap templates

  6. Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. via4d

  7. This is highly informatics, crisp and clear. I think that everything has been described in systematic manner so that reader could get maximum information and learn many things.

  8. This is a very interesting web page and I have enjoyed reading many of the articles and posts contained on the website, keep up the good work and hope to read some more interesting content in the future.torrentz2 proxy

  9. If you have been considering upgrading your dial-up connection to an internet service that is faster and more reliable, or if you have been eyeing different internet service providers (ISPs) who are offering different types of internet connection platforms, then one question has surely crossed your mind: what can broadband internet do for me? Broadband internet has become the most popular option for majority of internet users. Studies show that, in the US alone, broadband penetration is at a high 80%. Unblock Kickass

  10. I'm happy to see the considerable subtle element here!. office removals

  11. Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. 熊猫VPN 安全

  12. I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing. vpn china

  13. We ranked Surfshark as our number two 好用的VPN service out of the 78 that we’ve reviewed.
    That’s because it’s a powerful yet affordable VPN service with a ton of success in unblocking services like Netflix. It boasts an impressive server park featuring connections all over the world, and uses some of the most advanced encryption protocols out there.

  14. All your hard work is much appreciated. Nobody can stop to admire you. Lots of appreciation. website

  15. The proxy site should conceal your ip address just as worker URL to trick the proxy worker. Presently when you surf the web from a proxy, your proxy worker will comprehend that you are perusing a solitary site. This way you can peruse all impeded sites without an issue. best vpn reddit


Featured Post

The Retro Powershell - Looking good in 8-Bit | Part 1

I wrote a little script that, when placed in your PowerShell Profile, will print a message similar to the old boot message you got from you...