17
17
Checks whether the first string contains the second one
18
18
#>
19
19
20
- $accountName = ' account '
20
+ $accountName = ' fbs-aa-01 '
21
21
$location = " East US"
22
+ $resourceGroupName = " to-delete-01"
22
23
23
24
function AssertContains
24
25
{
@@ -46,19 +47,19 @@ function CreateRunbook
46
47
param ([string ] $runbookPath , [boolean ] $byName = $false , [string []] $tag , [string ] $description , [string ] $type = " PowerShell" )
47
48
48
49
$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 }
50
51
if ($runbook.Count -eq 1 )
51
52
{
52
53
$runbook | Remove-AzAutomationRunbook - Force
53
54
}
54
55
55
56
if (! $byName )
56
57
{
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
58
59
}
59
60
else
60
61
{
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
62
63
}
63
64
}
64
65
@@ -81,7 +82,7 @@ function WaitForJobStatus
81
82
{
82
83
Wait-Seconds $interval
83
84
$timeElapse = $timeElapse + $interval
84
- $job = Get-AzAutomationJob - AutomationAccount $accountName - Id $Id
85
+ $job = Get-AzAutomationJob - AutomationAccountName $accountName - ResourceGroupName $resourceGroupName - Id $Id
85
86
if ($job.Status -eq $Status )
86
87
{
87
88
break
@@ -104,7 +105,7 @@ function Test-RunbookWithParameter
104
105
param ([string ] $runbookPath , [string ] $type , [HashTable ] $parameters , [int ]$expectedResult )
105
106
106
107
# Setup
107
- $automationAccount = Get-AzAutomationAccount - Name $accountName
108
+ $automationAccount = Get-AzAutomationAccount - Name $accountName - ResourceGroupName $resourceGroupName
108
109
Assert-NotNull $automationAccount " Automation account $accountName does not exist."
109
110
110
111
$runbook = CreateRunbook $runbookPath - type $type
@@ -372,3 +373,30 @@ function Test-AutomationStartUnpublishedRunbook
372
373
Remove-AzAutomationRunbook $accountName - Name $runbook.Name - Force
373
374
Assert-Throws {Get-AzAutomationRunbook $accountName - Name $runbook.Name - Parameters $runbookParameters - PassThru - ErrorAction Stop}
374
375
}
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