Azure自动化:调用URL

时间:2015-05-11 10:04:13

标签: azure azure-automation

我是Azure自动化的新手。我希望每个工作日早上调用一个URL并获取其HTML。这就是我到目前为止所写的内容。

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
}

当我测试Runbook时,它没有在输出中给我HTML。相反,我在输出窗格中得到的是:

  

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

3 个答案:

答案 0 :(得分:2)

您的InlineScript目前只输出包含您脚本的字符串,因为您在整个表达式周围加上引号:

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

这就是你想要的:

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

答案 1 :(得分:0)

我正在使用Azure Runbook计划程序。我使用下面的代码触发了URL调用。

Function OutputStatus($type,$status) { 
    Write-Output "$type | $status"; 
}

Function Get-HTTPSStatus($url,$type) { 
    $HTTPSStatus = Invoke-WebRequest $url -Method Get –UseBasicParsing 
    if ($HTTPSStatus.StatusCode -eq "200") { 
     return OutputStatus -type $type -status "Success" 
    } else { 
     return OutputStatus -type $type -status "Error" 
    } 
}
Get-HTTPSStatus "http://www.google.com" "Google Website"

来源:https://sharepointyankee.com/2018/01/29/creating-runbooks-in-azure-and-calling-them-from-sharepoint-using-webhooks-and-flow/

答案 2 :(得分:-1)

这应该是比使用Webclient

更简单的方法

$output = (Invoke-WebRequest -Uri http://www.google.com -UseBasicParsing).Content