Hi,
i'm getting some problem (bug?) with azure automation runbook.
Last week i converted this script from 5.1 to 7.1 preview:
$connectionResult = Connect-AzAccount -Identity
$connectionResult
##### SCRIPT START ST
$AppGwlist = Get-AzApplicationGateway
foreach ($AppGw in $AppGwlist)
{
$Gw = Get-AzApplicationGateway -ResourceGroupName $AppGw.ResourceGroupName -Name $AppGw.Name
Start-AzApplicationGateway -ApplicationGateway $Gw
}
Start-Sleep -Seconds 10
$Apselist = Get-AzWebApp
foreach ($Apse in $Apselist)
{
Start-AzWebApp -ResourceGroupName $Apse.ResourceGroup -Name $Apse.Name
$ApseSlotlist = Get-AzWebAppSlot -ResourceGroupName $Apse.ResourceGroup -Name $Apse.Name
if ($ApseSlotlist -ne $null){
foreach ($ApseSlotAll in $ApseSlotlist){
Start-AzWebAppSlot -ResourceGroupName $Apse.ResourceGroup -Name $Apse.Name -Slot $ApseSlotAll.Name.Split("/")[1]
}
}
}
In this case script start app gateway and app service. I used 7.1 to use parallel foreach and i did this:
$connectionResult = Connect-AzAccount -Identity
$connectionResult
##### SCRIPT START ST
$AppGwlist = Get-AzApplicationGateway | ForEach-Object {
$z = @{}
foreach($prop in $_.PSObject.Properties) {
$z[$prop.Name] = $prop.Value
}
$z
}
$AppGwlist | ForEach-Object -Parallel {
function Splatting {
param($Name, $ResourceGroupName)
$Gw = Get-AzApplicationGateway -ResourceGroupName $ResourceGroupName -Name $Name
Start-AzApplicationGateway -ApplicationGateway $Gw
}
Splatting @_
} -ThrottleLimit 10
Start-Sleep -Seconds 60
$Apselist = Get-AzWebApp | ForEach-Object {
$z = @{}
foreach($prop in $_.PSObject.Properties) {
$z[$prop.Name] = $prop.Value
}
$z
}
$Apselist | ForEach-Object -Parallel {
function Splatting {
param($Name, $ResourceGroupName)
Start-AzWebApp -ResourceGroupName $ResourceGroupName -Name $Name
$ApseSlotlist = Get-AzWebAppSlot -ResourceGroupName $ResourceGroupName -Name $Name
if ($ApseSlotlist -ne $null){
foreach ($ApseSlotAll in $ApseSlotlist){
Start-AzWebAppSlot -ResourceGroupName $ResourceGroupName -Name $Name -Slot $ApseSlotlist.Name.Split("/")[1]
}
}
}
Splatting @_
} -ThrottleLimit 10
Script working, but when i invoke it via webhook, script goes in failed without any error. On postman i got 202, script run but suddenly go in failed. I reconfigured old script with 5.1 and webhook start to work as usual. There is something changeng in webhook invokation with 7.1 runtime?
To bypass webhook problem, now i am using it again 5.1 runtime. I converted my script with start-job and workflow to parallelize it
$connectionResult = Connect-AzAccount -Identity
$connectionResult
### EXCLUSIONS
$ApseExclusion = ''
$AppGwExclusion = ''
### STOP APSE
$ScriptBlockApse = {
param($ApseName,$RgApse)
if ($ApseName -notin $ApseExclusion){
Stop-AzWebApp -ResourceGroupName $RgApse -Name $ApseName
$ApseSlotlist = Get-AzWebAppSlot -ResourceGroupName $RgApse -Name $ApseName
if ($ApseSlotlist -ne $null){
foreach ($ApseSlotAll in $ApseSlotlist){
Stop-AzWebAppSlot -ResourceGroupName $RgApse -Name $ApseName -Slot $ApseSlotAll.Name.Split("/")[1]
}
}
}
}
$ApseList = Get-AzWebApp
foreach($Apse in $ApseList) {
# Execute the jobs in parallel
$ApseName = $Apse.Name
$RgApse = $Apse.ResourceGroup
Start-Job $ScriptBlockApse -ArgumentList $ApseName, $RgApse
}
# Wait for all to complete
While (Get-Job -State "Running") { Start-Sleep 5 }
# Display output from all jobs
$res += (Get-Job | Receive-Job)
# Cleanup
Remove-Job *
Start-Sleep -Seconds 10
### STOP APPGW
$ScriptBlockAppGw = {
param($AppGwName,$RgAppGw)
if ($AppGwName -notin $AppGwExclusion){
$Gw = Get-AzApplicationGateway -ResourceGroupName $RgAppGw -Name $AppGwName
Stop-AzApplicationGateway -ApplicationGateway $Gw
}
}
$AppGwList = Get-AzApplicationGateway
foreach($AppGw in $AppGwList) {
# Execute the jobs in parallel
$AppGwName = $AppGw.Name
$RgAppGw = $AppGw.ResourceGroupName
Start-Job $ScriptBlockAppGw -ArgumentList $AppGwName, $RgAppGw
}
# Wait for all to complete
While (Get-Job -State "Running") { Start-Sleep 5 }
# Display output from all jobs
$res += (Get-Job | Receive-Job)
# Cleanup
Remove-Job *
with workflow
$connectionResult = Connect-AzAccount -Identity
$connectionResult
### STOP APSE
workflow test {
$ApseList = Get-AzWebApp
foreach -parallel ($in in $ApseList){
Stop-AzWebApp -ResourceGroupName $in.ResourceGroupName -Name $in.name
$ApseSlotlist = Get-AzWebAppSlot -ResourceGroupName $in.ResourceGroupName -Name $in.name
if ($ApseSlotlist -ne $null){
foreach ($ApseSlotAll in $ApseSlotlist){
Stop-AzWebAppSlot -ResourceGroupName $in.ResourceGroupName -Name $in.name -Slot $ApseSlotAll.Name.Split("/")[1]
}
}
}
}
but i'm getting this error:
Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=mytoken' or one of its dependencies. The system cannot find the file specified.
I'm getting crazy becouse locally, with powershell ise they are working.
I have to install something or there is some broke in my code?
Thanks