问题
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");
回答1:
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"); }
回答2:
I'm using Azure Runbook scheduler. I used code below to trigger an URL call.
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"
Source: https://sharepointyankee.com/2018/01/29/creating-runbooks-in-azure-and-calling-them-from-sharepoint-using-webhooks-and-flow/
回答3:
This should be a more simple approach than using the Webclient
$output = (Invoke-WebRequest -Uri http://www.google.com -UseBasicParsing).Content
来源:https://stackoverflow.com/questions/30164766/azure-automation-calling-a-url