12

The following PowerShell invoke-webrequest works for me when the Windows Service I'm running it from has permission to call the webservice. However, this isn't always the case.

I need to the ability to use Windows Authentication but also set the account username\password for the call. Does anyone have some sample code for doing this?

Invoke-WebRequest -UseBasicParsing "url" -UseDefaultCredentials -Method GET
1

1 Answer 1

14

You may set the UseDefaultCredentials property of Invoke-WebRequest module to true.

Official doc

$url = "http://yourURL"
$wc = New-Object System.Net.WebClient
$wc.UseDefaultCredentials = $true
$response = $wc.DownloadString($url)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your response I am using UseDefaultCredentials in my original post. I need to use WindowsAuthentication but specify the Username\Password for the account I want to use. I do not want to use the default credentials associated with the process executing the powershell script.
Then, you might need to use -Authentication along with -Credential props

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.