Chapter 12. Internet-Enabled Scripts
Although PowerShell provides an enormous benefit even when your scripts interact only with the local system, working with data sources from the Internet opens exciting and unique opportunities. For example, you might download files or information from the Internet, interact with a web service, store your output as HTML, or even send an email that reports the results of a long-running script.
Through its cmdlets and access to the networking support in the .NET Framework, PowerShell provides ample opportunities for Internet-enabled administration.
Download a File from an FTP or Internet Site
You want to download a file from an FTP location or website on the Internet.
PS > $source = "http://www.leeholmes.com/favicon.ico" PS > $destination = "c:\temp\favicon.ico" PS > PS > Invoke-WebRequest $source -OutFile $destination
Invoke-WebRequest cmdlet lets you easily
upload and download data from remote web servers. It acts much like a
web browser in that you can specify a user agent, a proxy (if your
outgoing connection requires one), and even credentials.
If you require a solution that works with PowerShell version 2,
DownloadFile() method of
System.Net.WebClient class from
the .NET Framework.
While the Solution demonstrates downloading a file from a web
(HTTP) resource, the
Invoke-WebRequest cmdlet also supports FTP locations. To specify an FTP ...