简体   繁体   中英

How to pass json file as parameter to azure powershell runbook?

I'm trying to deploy sentinel alerts into sentinel using azure runbook by using the below command:

Import-AzSentinelAlertRule -WorkspaceName "xxx" -SettingsFile "test_alert.json" 

The SettingsFile of this command expects a path of json as parameter. How we can pass the json file to runbook?

Can anyone please suggest me out?

How we can pass the json file to runbook?

I have reproduced in my environment and I followed Microsoft-Document and I got expected results as below:

Param(
[parameter(Mandatory=$true)]
[object]$json
)
$json = $json | ConvertFrom-Json

在此处输入图像描述

Then save and publish runbook.

Then open your local windows PowerShell and follow below steps:

Step1:

Connect-AzAccount

在此处输入图像描述

Step2:

 $json =  (Get-content -path "C:Downloads\xy.json") | Out-string
 

在此处输入图像描述

Step3:

$RBParams = @{
     AutomationAccountName = 'rithwikrunning'
     ResourceGroupName = 'XX'
     Name = 'xy'
     Parameters = $JsonParams
}

XX- Name of the resource Group xy- Name of the runbook

在此处输入图像描述

Step4:

$job = Start-AzAutomationRunbook @RBParams

在此处输入图像描述

Now the json file is passed to run book and it got started:

在此处输入图像描述

Now the content of the file or file is in $json variable in runbook.

References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM