powershell - How to catch specific start-bitstransfer "Proxy authentication is required" exception? -


No matter what I do, I can not catch exceptions like this:

  Start -Bit transfer: HTTP status 407: Proxy authentication is required. On-line: 4 char: 6 + Start BitsTransfer source $ url -Destination $ fullpath + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo: InvalidOperation: (:) [START- BitsTransfer], except + FullyQualifiedErrorId: StartBitsTransferCOMException, Microsoft.BackgroundIntelligentTransfer.Management. NewBitsTransferCommand   

I can not use "invoke-command" and [System.Management.Automation.RuntimeException] (PSRemotingTransportException) because bits when remote scriptblock is not supported running.

How to do this?

There is no direct answer to your question, but to view it as a pre-effective solution Check whether proxy authentication is necessary before starting your BITS transfers. It will not catch that error, but it will effectively test for the same condition and allow you to compensate for it.

What can you do a System.Net.WebClient item and see whether proxy authentication is required or not:

  $ WC = new-object System.Net.WebClient $ ProxyAuth = $ WC.Proxy.IsBypassed ( "http: // www. now if you are behind a proxy  $ ProxyAuth  would be perfect, so you need And if you are doing PSv3 or higher running you can setup the default parameter for the  Start-BitsTransfer  provided credentials Defense to use:  
  if ($ ProxyAuth) {$ ProxyCred = Get-Credential - Message Enter $ PSDefaultParameterValues.Add "credentials for proxy authentication" ( "Start BitsTransfer: ProxyAuthentication "," basic ") $ PSDefaultParameterValues.Add (" Start BitsTransfer: ProxyCredential ", $ ProxyCred)}   

now you run the script and if need proxy authentication Ask for credentials, then make your transfer.

There's a lot to get from this, or from Was Kulit.

Comments

Popular posts from this blog

python - Writing Greek in matplotlib labels, titles -

c# - LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method -

Pygame memory leak with transform.flip -