Search code examples
powershellinvoke-command

How to make multi-line uri using invoke-webrequest in Powershell


I'm trying to concatenate my uri in this invoke so that I can have each variable on a separate line. That way I can make changes easier and don't have to search as hard. I was able to do this in a bash script, but am at a loss for how to do this in Powershell.

Line as follows:

Invoke-WebRequest -Uri (beginning of url)?date=$date"&"time=$time"&"name=$env:computername"&"loginid=$env:username"&"sn=$serialnumber"&"ipaddr=$ipaddr"&"verb=profileclear

Thanks!


Solution

  • I think the easiest way of achieving this would be like this:

    $uri = "Https://something.somewhere/?" +
        "date=$date&" + 
        "time=$time&" + 
        "name=$env:computername&" + 
        "loginid=$env:username&" + 
        "sn=$serialnumber&" + 
        "ipaddr=$ipaddr&" + 
        "verb=profileclear" 
    
    Invoke-WebRequest -Uri $uri