0

There is a script:

$html = Invoke-WebRequest -Uri https://www.mcafee.com/enterprise/en-us/downloads/security-updates.html
$dathtml = ($html.parsedhtml.getelementsbytagname("TR") |% { ( $_.children | ?{ $_.tagName -eq "td"} | % innerText ) } | Select-Object -First 1).Split('xdat')[0] 
Write-Host $dathtml

The problem is the following:

Invoke-WebRequest : ERROR
Cache Access Denied.
The following error was encountered while trying to retrieve the URL: https://www.mcafee.com/*
Cache Access Denied.
Sorry, you are not currently allowed to request https://www.mcafee.com/* from this cache until you have authenticated yourself.
Please contact the cache administrator if you have difficulties authenticating yourself.
Generated Wed, 25 Jul 2018 09:49:32 GMT by xxxxx (xxxx)
At line:1 char:9
+ $html = Invoke-WebRequest -Uri https://www.mcafee.com/enterprise/en-u ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
You cannot call a method on a null-valued expression.
At line:2 char:1
+ $dathtml = ($html.parsedhtml.getelementsbytagname("TR") |% { ( $_.chi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Is there any way to integrate the proxy server authentication method into the script ( AD auth ). If I run this script on my computer ( without proxy, on public net etc... ) it works. But I have to run this script from another computer which use proxy, the site is allowed but not able to get the information what I need. Any suggestion? Thanks

2 Answers 2

3

Invoke-WebRequest has a -ProxyCredential argument.

Use a credentials object there. (username should be in the form "Domain\name")

You can do:

$cred = Get-Credential -Message 'Please enter your credentials for the proxy server.'
if ($cred) { 
    $url  = "https://www.mcafee.com/enterprise/en-us/downloads/security-updates.html"
    $html = Invoke-WebRequest -Uri $url -ProxyCredential $cred
    # the rest of your code goes here
}

I cannot help you with the actual McAfee commands needed. For that you should search the McAfee communities and it will depend on the product you want to update.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer but how and where can I use this? How it will be look like in my script? I'm a beginner in this :/ Thank you for Your Help!
Thanks for the help. With this and a little google search it's working fine :)
0

You can also add authentication headers to the web request, as explained here

Comments

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.