New to Powershell

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Jason Colotario Jason Colotario 10 months, 2 weeks ago.

  • Author
    Posts
  • #34480
    Profile photo of Stephen Jones
    Stephen Jones
    Participant

    Greeting all,

    I'm new to powershell and trying to figure out a way to automate some of my tasks. One such task is the recurring updates for Java. I've begun working on a script and the first part downloads the installer from Java using the following:

    Invoke-WebRequest -uri "http://javadl.sun.com/webapps/download/AutoDL?BundleId=114687" -OutFile c:\temp

    However, every time I run this command I get the following error:

    Invoke-WebRequest : Access to the path 'C:\temp' is denied.
    At line:1 char:1
    + Invoke-WebRequest -uri "http://javadl.sun.com/webapps/download/AutoDL?BundleId=1 ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Invoke-WebRequest], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

    I'm running the command as Administrator, have my execution policy set to remote signed and have provided full control to the directory but still unsure why I keep getting a access denied error. I know I'm committing a simple error but not sure what I've done wrong. Can anyone point me in the right direction?

  • #34481
    Profile photo of Joseph Monarch
    Joseph Monarch
    Participant

    Try this

    C:\Temp\Randomfilename.txt

  • #34482
    Profile photo of Stephen Jones
    Stephen Jones
    Participant

    Thanks Joseph, that did it.

  • #34497
    Profile photo of Jason Colotario
    Jason Colotario
    Participant

    Looks like POSH needed a specified target file? OR would it have succeeded if the folder/path included the closing \

    Example "c:\temp\" instead of "c:\temp"

    Regards,

    Jason

You must be logged in to reply to this topic.