If you have a Unix/Linux background you are probably familiar with curl och wget, which are very useful utilities for sending HTTP requests from the command line. If you also manage Windows servers in some way you might also have found that Windows has not historically shipped with any proper substitute for curl/wget.
PowerShell has revolutionized server management on the Windows side, by embracing the Unix/Linux way of server management. However, it is still quite young so the library of available cmdlets is still growing. In version 4 of PowerShell, Microsoft finally included a cmdlet called Invoke-WebRequest, which does just what its name implies.
You can check what version of PowerShell you are running on your system by invoking the following command in PowerShell:
If you have an earlier version of PowerShell you can upgrade by installing the Windows Management Framework 4.0. After installing that, and rebooting your system, you should be able to find the Invoke-WebRequest command.
You can now send an HTTP request like this:
Invoke-WebRequest <url> -method <method>
For example, if you want to delete all indices in a local ElasticSearch instance:
Invoke-WebRequest http://localhost:9200/* -method DELETE
For more details on how to use the Invoke-WebRequest cmdlet, use the PowerShell cmdlet Get-Help:
If you are interested in more usage examples, you can get those via the help as well:
Get-Help Invoke-WebRequest -examples | more
Piping the output through
more lets you read the output of the help command page by page, instead of having to scroll back to find the start of the command output.
If you would rather read about the command at Technet, use the
Get-Help Invoke-WebRequest -online