Search code examples
azureazure-automation

Azure Automation: Calling a URL


I am new to Azure Automation. I want to call a URL and get its HTML once every weekday morning. This is what I have written so far.

workflow Wakeup-Url
{
    Param 
    (  
        [parameter(Mandatory=$true)]
        [String] 
        $Url
    )

    $day = (Get-Date).DayOfWeek
    if ($day -eq 'Saturday' -or $day -eq 'Sunday'){
        exit
    }

    $output = ""
    InlineScript {"$Using:output = (New-Object System.Net.WebClient).DownloadString(`"$Using:Url`");"}
    write-output $output
}

Its not giving me the HTML in the output when I test the runbook. Instead what I get in the output pane is:

= (New-Object System.Net.WebClient).DownloadString("https://my.url.com/abc.html");


Solution

  • Your InlineScript is currently just outputting a string containing your script, since you put quotes around the entire expression:

    InlineScript {"$Using:output = (New-Object System.Net.WebClient).DownloadString(`"$Using:Url`");"}
    

    This is what you want I think:

    $output = InlineScript { (New-Object System.Net.WebClient).DownloadString("$Using:Url"); }