1717Checks whether the first string contains the second one
1818#>
1919
20- $accountName = ' account '
20+ $accountName = ' fbs-aa-01 '
2121$location = " East US"
22+ $resourceGroupName = " to-delete-01"
2223
2324function AssertContains
2425{
@@ -46,19 +47,19 @@ function CreateRunbook
4647 param ([string ] $runbookPath , [boolean ] $byName = $false , [string []] $tag , [string ] $description , [string ] $type = " PowerShell" )
4748
4849 $runbookName = gci $runbookPath | % {$_.BaseName }
49- $runbook = Get-AzAutomationRunbook $accountName | where {$_.Name -eq $runbookName -and $_.RunbookType -eq $type }
50+ $runbook = Get-AzAutomationRunbook - AutomationAccountName $accountName - ResourceGroupName $resourceGroupName | where {$_.Name -eq $runbookName -and $_.RunbookType -eq $type }
5051 if ($runbook.Count -eq 1 )
5152 {
5253 $runbook | Remove-AzAutomationRunbook - Force
5354 }
5455
5556 if (! $byName )
5657 {
57- return New -AzAutomationRunbook $accountName - Path $runbookPath - Tag $tag - Description $description - Type $type
58+ return Import -AzAutomationRunbook - AutomationAccountName $accountName - ResourceGroupName $resourceGroupName - Path $runbookPath - Tag $tag - Description $description - Type $type
5859 }
5960 else
6061 {
61- return New-AzAutomationRunbook $accountName - Name $runbookName - Tag $tag - Description $description - Type $type
62+ return New-AzAutomationRunbook - AutomationAccountName $accountName - ResourceGroupName $resourceGroupName - Name $runbookName - Tag $tag - Description $description - Type $type
6263 }
6364}
6465
@@ -81,7 +82,7 @@ function WaitForJobStatus
8182 {
8283 Wait-Seconds $interval
8384 $timeElapse = $timeElapse + $interval
84- $job = Get-AzAutomationJob - AutomationAccount $accountName - Id $Id
85+ $job = Get-AzAutomationJob - AutomationAccountName $accountName - ResourceGroupName $resourceGroupName - Id $Id
8586 if ($job.Status -eq $Status )
8687 {
8788 break
@@ -104,7 +105,7 @@ function Test-RunbookWithParameter
104105 param ([string ] $runbookPath , [string ] $type , [HashTable ] $parameters , [int ]$expectedResult )
105106
106107 # Setup
107- $automationAccount = Get-AzAutomationAccount - Name $accountName
108+ $automationAccount = Get-AzAutomationAccount - Name $accountName - ResourceGroupName $resourceGroupName
108109 Assert-NotNull $automationAccount " Automation account $accountName does not exist."
109110
110111 $runbook = CreateRunbook $runbookPath - type $type
@@ -372,3 +373,30 @@ function Test-AutomationStartUnpublishedRunbook
372373 Remove-AzAutomationRunbook $accountName - Name $runbook.Name - Force
373374 Assert-Throws {Get-AzAutomationRunbook $accountName - Name $runbook.Name - Parameters $runbookParameters - PassThru - ErrorAction Stop}
374375}
376+
377+
378+ <#
379+ . SYNOPSIS
380+ Tests Runbook with Parameters and Wait
381+ #>
382+ function Test-RunbookWithParameterAndWait
383+ {
384+ param ([string ] $runbookPath , [string ] $type , [HashTable ] $parameters , [int ]$expectedResult )
385+
386+ # Setup
387+ $automationAccount = Get-AzAutomationAccount - Name $accountName - ResourceGroupName $resourceGroupName
388+ Assert-NotNull $automationAccount " Automation account $accountName does not exist."
389+
390+ $runbook = CreateRunbook $runbookPath - type $type
391+ Assert-NotNull $runbook " runBook $runbookPath does not import successfully."
392+ $automationAccount | Publish-AzAutomationRunbook - Name $runbook.Name
393+
394+ # Test
395+ $job = $automationAccount | Start-AzAutomationRunbook - Name $runbook.Name - Parameters $parameters - Wait
396+ Assert-NotNull $job
397+ [int ]$Result = $job [$job.Length - 1 ]
398+ Assert-AreEqual $expectedResult $Result
399+
400+ $automationAccount | Remove-AzAutomationRunbook - Name $runbook.Name - Force
401+ Assert-Throws { $automationAccount | Get-AzAutomationRunbook - Name $runbook.Name }
402+ }
0 commit comments