Thursday, December 25, 2014

#37 : Download Files from Internet with Powershell

Powershell can be used to download a file from internet. This might help you matching some item from internet or you can create a download manager kind of software in Powershell.
Actually, you can do nearly everything which you can do in C# or any .NET based programming language because, .NET framework is common to C#, VB.NET and Powershell as well. Both Powershell or C# compile the code into MSIL (Microsoft Intermediate Language). But the only difference is Powershell is in form of script and C# will be a program. 
Powershell scripts can be compiled using C#, but again the compiled executable will require Powershell be installed on the machine. This cannot be called as standalone executable, but again I think "Can you run a C# code when .NET framework is not installed?". Anyways, lets not waste more time in thinking, below is the piece of code- 

(new-object System.Net.WebClient).Downloadfile("http://www.freeware995.com/bin/pdfedit.exe", "d:\pdfedit.exe")

Above is smallest inner line of a possible big code which will handle download of files from Internet. 

For sake of simplicity, I always prefer to give a one-liner. The reason is, when you want to know how to do something, your intention is basically to get something too small which can be further enhanced in your program. When I search, I look for a small code and I hope everyone does. There is no point is providing a complex code which you could not understand or incorporate in your code!

Enjoy scripting!!

No comments:

Post a Comment

#112: How to handle xml document in Powershell?

 In PowerShell, you can handle XML data using various cmdlets and methods provided by the .NET Framework. Here's a basic guide on how to...