Struggling to get Skype to download over Powershell 2.0

-1

I'm having difficulty with a batch file I created to aid in downloading, and updating Skype. The part that isn't working is the bit which downloads Skype itself. Most of the machines I'm supporting are running Powershell 2.0, and would be difficult to bring up to at least 3.0

Please see below the code that I'm using:

powershell -Command "(New-Object Net.Webclient).DownloadFile('https://go.skype.com/skype.download', 'C:\Temp\Skype-Setup.exe')"

The error message I receive in the command window is as followed:

Exception calling "DownloadFile" with "2" argument(s): "An exception occurred d
uring a WebClient request."
At line:1 char:40
+ (New-Object Net.Webclient).DownloadFile <<<< ('https://go.skype.com/skype.dow
nload', 'C:\Temp\Skype-Setup.exe')
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

I've tried googling the errors separately, but haven't been able to find any results. Any help would be greatly appreciated.

user961133

Posted 2018-11-06T16:44:47.807

Reputation:

I googled "Powershell 2.0 Download File" and the first link was https://stackoverflow.com/questions/31523709/downloading-files-with-powershell-2-0-on-windows-7 - Does that resolve your issue? By the way, the code your provided works in PS 5.1, sorry you can't upgrade. Also, this should be asked on StackExchange as it's more of a programming question than a computer software question.

– Andrew – 2018-11-06T18:00:29.760

@reeves Powershell questions are on topic here. Please don't suggest they should be migrated. – DavidPostill – 2018-11-06T18:25:36.960

@DavidPostill Thank you for clearing that up. I misinterpreted the Help Center's on and off-topic information about "Programming and Software Development". – Andrew – 2018-11-06T18:36:39.240

@Reeves No problem. Pure programming is off topic, but scripting (PS, VBA, cmd, bash, etc) are on topic. – DavidPostill – 2018-11-06T18:41:23.403

Answers

1

I figured it out, if the directory it wants to save to doesn't exist, it throws up the DotNetMethodException error. So my Powershell scripting was fine, I just didn't realise it couldn't create a directory. My bad.

I actually found this out through the link that was posted above, thanks for all your help :)

EDIT: For anyone wondering, the code I used to fix this is below.

IF exist C:\Temp\ ( echo Temp Exists ) ELSE ( mkdir C:\Temp\ && echo Temp Created )

user961133

Posted 2018-11-06T16:44:47.807

Reputation: