1717Checks whether the first string contains the second one
1818#>
1919
20- $accountName = ' AutomationAccount'
20+ $accountName = ' safeer'
21+ $location = " East US"
2122
2223function AssertContains
2324{
@@ -108,10 +109,10 @@ function Test-RunbookWithParameter
108109
109110 $runbook = CreateRunbook $runbookPath
110111 Assert-NotNull $runbook " runBook $runbookPath does not import successfully."
111- $automationAccount | Publish-AzureAutomationRunbook - Id $runbook.Id
112+ $automationAccount | Publish-AzureAutomationRunbook - Name $runbook.Name
112113
113114 # Test
114- $job = $automationAccount | Start-AzureAutomationRunbook - Id $runbook.Id - Parameters $parameters
115+ $job = $automationAccount | Start-AzureAutomationRunbook - Name $runbook.Name - Parameters $parameters
115116 WaitForJobStatus - Id $job.Id - Status " Completed"
116117 $jobOutput = $automationAccount | Get-AzureAutomationJobOutput - Id $job.Id - Stream Output
117118 $automationAccount | Remove-AzureAutomationRunbook - Name $runbook.Name - Force
@@ -126,16 +127,15 @@ function Test-AutomationStartAndStopRunbook
126127{
127128 param ([string ] $runbookPath )
128129
129- # Setup
130- $automationAccount = Get-AzureAutomationAccount - Name $accountName
130+ $automationAccount = Get-AzureAutomationAccount - Name $accountName
131131 Assert-NotNull $automationAccount " Automation account $accountName does not exist."
132132
133133 $runbook = CreateRunbook $runbookPath
134134 Assert-NotNull $runbook " runBook $runbookPath does not import successfully."
135- $automationAccount | Publish-AzureAutomationRunbook - Id $runbook.Id
135+ $automationAccount | Publish-AzureAutomationRunbook - Name $runbook.Name
136136
137137 # Test
138- $job = $automationAccount | Start-AzureAutomationRunbook - Id $runbook.Id
138+ $job = Start-AzureAutomationRunbook - Name $runbook.Name - AutomationAccountName $accountName
139139 WaitForJobStatus - Id $job.Id - Status " Running"
140140 $automationAccount | Stop-AzureAutomationJob - Id $job.Id
141141 WaitForJobStatus - Id $job.Id - Status " Stopped"
@@ -153,31 +153,28 @@ function Test-AutomationPublishAndEditRunbook
153153
154154 $runbook = CreateRunbook $runbookPath $true
155155
156- # Test
157-
158- Assert-Null $runbook.PublishedRunbookVersionId
159- Assert-NotNull $runbook.DraftRunbookVersionId
160156 # Publish Runbook
161- $publishedRunbook = Publish-AzureAutomationRunbook $accountName - Id $runbook.Id
162- Assert-NotNull $publishedRunbook.PublishedRunbookVersionId
163- Assert-Null $publishedRunbook.DraftRunbookVersionId
164- $publishedRunbookDefn = Get-AzureAutomationRunbookDefinition $accountName - VersionId $publishedRunbook.PublishedRunbookVersionId
157+ Publish-AzureAutomationRunbook $accountName - Name $runbook.Name
158+ $publishedRunbook = Get-AzureAutomationRunbook $accountName - Name $runbook.Name
159+ $runbookState = " Published"
160+ Assert-AreEqual $publishedRunbook.State $runbookState " Runbook should be in $runbookState state"
161+ $publishedRunbookDefn = Get-AzureAutomationRunbookDefinition $accountName - Name $runbook.Name
165162
166163 # Edit Runbook
167- Set-AzureAutomationRunbookDefinition $accountName - Id $runbook.Id - Path $runbookPath - Overwrite
164+ Set-AzureAutomationRunbookDefinition $accountName - Name $runbook.Name - Path $runbookPath - Overwrite
168165 $runbook = Get-AzureAutomationRunbook $accountName - Name $runbook.Name
169- Assert-AreEqual $publishedRunbook .PublishedRunbookVersionId $runbook .PublishedRunbookVersionId
170- Assert-NotNull $runbook.DraftRunbookVersionId " Runbook should be in draft mode "
171- $editedRunbookDefn = Get-AzureAutomationRunbookDefinition $accountName - VersionId $runbook.DraftRunbookVersionId
166+ $runbookState = " Edit "
167+ Assert-AreEqual $runbook.State $runbookState " Runbook should be in $runbookState state "
168+ $editedRunbookDefn = Get-AzureAutomationRunbookDefinition $accountName - Name $runbook.Name - Slot " Draft "
172169 Assert-AreNotEqual $editedRunbookDefn.Content $publishedRunbookDefn.Content " Old content and edited content of the runbook shouldn't be equal"
173170
174171 Assert-Throws {Set-AzureAutomationRunbookDefinition $accountName - Name $runbook.Name - Path $editRunbookPath - PassThru - ErrorAction Stop}
175172 Set-AzureAutomationRunbookDefinition $accountName - Name $runbook.Name - Path $editRunbookPath - Overwrite
176- $editedRunbookDefn2 = Get-AzureAutomationRunbookDefinition $accountName - VersionId $runbook.DraftRunbookVersionId
173+ $editedRunbookDefn2 = Get-AzureAutomationRunbookDefinition $accountName - Name $runbook.Name - Slot " Draft "
177174 Assert-AreNotEqual $editedRunbookDefn2.Content $editedRunbookDefn.Content " Old content and edited content of the runbook shouldn't be equal"
178175
179- Remove-AzureAutomationRunbook $accountName - Id $runbook.Id - Force
180- Assert-Throws {Get-AzureAutomationRunbook $accountName - Id $runbook.Id }
176+ Remove-AzureAutomationRunbook $accountName - Name $runbook.Name - Force
177+ Assert-Throws {Get-AzureAutomationRunbook $accountName - Name $runbook.Name }
181178
182179}
183180
@@ -194,30 +191,26 @@ function Test-AutomationConfigureRunbook
194191 Assert-NotNull $automationAccount " Automation account $accountName does not exist."
195192 $runbook = CreateRunbook $runbookPath
196193 Assert-NotNull $runbook " runbook ($runbookPath ) isn't imported successfully."
197- Publish-AzureAutomationRunbook - Id $runbook.Id - AutomationAccountName $accountName
194+ Publish-AzureAutomationRunbook - Name $runbook.Name - AutomationAccountName $accountName
198195
199196 # Test
200197
201198 # Change the runbook configuration
202- $automationAccount | Set-AzureAutomationRunbook - Id $runbook.Id - LogDebug $true - LogVerbose $true - LogProgress $false
199+ $automationAccount | Set-AzureAutomationRunbook - Name $runbook.Name - LogVerbose $true - LogProgress $false
203200 $runbook = $automationAccount | Get-AzureAutomationRunbook - Name $runbook.Name
204201 Assert-NotNull $runbook " Runbook shouldn't be Null"
205- Assert-AreEqual $true $runbook.LogDebug " Log Debug mode should be true."
206202 Assert-AreEqual $true $runbook.LogVerbose " Log Verbose mode should be true."
207203 Assert-AreEqual $false $runbook.LogProgress " Log Progress mode should be false."
208204
209205 # Start runbook and wait for job complete
210- $job = $automationAccount | Start-AzureAutomationRunbook - Id $runbook.Id
206+ $job = $automationAccount | Start-AzureAutomationRunbook - Name $runbook.Name
211207 WaitForJobStatus - Id $job.Id - Status " Completed"
212208
213209 # Check job output streams
214210 $jobOutputs = $automationAccount | Get-AzureAutomationJobOutput - Id $job.Id - Stream " Output"
215211 Assert-AreEqual 1 $jobOutputs.Count
216212 AssertContains $jobOutputs [0 ].Text " output message" " The output stream is wrong."
217- # Verify that debug and verbose streams are logged
218- $jobDebugOutputs = $automationAccount | Get-AzureAutomationJobOutput - Id $job.Id - Stream " Debug"
219- Assert-AreEqual 1 $jobDebugOutputs.Count
220- AssertContains $jobDebugOutputs [0 ].Text " debug message" " The debug stream is wrong."
213+ # Verify that verbose streams are logged
221214 $jobVerboseOutputs = Get-AzureAutomationJobOutput $accountName - Id $job.Id - Stream " Verbose"
222215 Assert-AreEqual 1 $jobVerboseOutputs.Count
223216 AssertContains $jobVerboseOutputs [0 ].Text " verbose message" " The verbose stream is wrong."
@@ -226,26 +219,24 @@ function Test-AutomationConfigureRunbook
226219 Assert-AreEqual 0 $jobProgressOutputs.Count
227220
228221 # Change the runbook configuration again and start the runbook
229- Set-AzureAutomationRunbook $accountName - Id $runbook.Id - LogDebug $false - LogVerbose $false - LogProgress $true
222+ Set-AzureAutomationRunbook $accountName - Name $runbook.Name - LogVerbose $false - LogProgress $true
230223 $job = Start-AzureAutomationRunbook $accountName - Name $runbook.Name
231224 WaitForJobStatus - Id $job.Id - Status " Completed"
232225 # Verify that progress stream is logged
233226 $jobProgressOutputs = Get-AzureAutomationJobOutput $accountName - Id $job.Id - Stream " Progress"
234227 Assert-AreNotEqual 0 $jobProgressOutputs.Count
235228 Assert-AreEqual $jobProgressOutputs [0 ].Type " Progress"
236- # Verify that debug and verbose streams aren't logged
237- $jobDebugOutputs = Get-AzureAutomationJobOutput $accountName - Id $job.Id - Stream " Debug"
238- Assert-AreEqual 0 $jobDebugOutputs.Count
229+ # Verify that verbose streams aren't logged
239230 $jobVerboseOutputs = Get-AzureAutomationJobOutput $accountName - Id $job.Id - Stream " Verbose"
240231 Assert-AreEqual 0 $jobVerboseOutputs.Count
241232
242233 # Check whether the total number of jobs for the runbook is correct
243- $jobs = Get-AzureAutomationJob $accountName - RunbookId $runbook.Id
234+ $jobs = Get-AzureAutomationJob $accountName - RunbookName $runbook.Name
244235 Assert-AreEqual 2 $jobs.Count " There should be 2 jobs in total for this runbook."
245236
246237 # Remove runbook
247238 $automationAccount | Remove-AzureAutomationRunbook - Name $runbook.Name - Force
248- Assert-Throws {$automationAccount | Get-AzureAutomationRunbook - Id $runbook.Id }
239+ Assert-Throws {$automationAccount | Get-AzureAutomationRunbook - Name $runbook.Name }
249240}
250241
251242<#
@@ -263,17 +254,17 @@ function Test-AutomationSuspendAndResumeJob
263254
264255 # Test
265256
266- $automationAccount | Publish-AzureAutomationRunbook - Id $runbook.Id
257+ $automationAccount | Publish-AzureAutomationRunbook - Name $runbook.Name
267258 # Start, suspend, and then resume job
268- $job = Start-AzureAutomationRunbook $accountName - Id $runbook.Id
259+ $job = Start-AzureAutomationRunbook $accountName - Name $runbook.Name
269260 WaitForJobStatus - Id $job.Id - Status " Running"
270261 Suspend-AzureAutomationJob $accountName - Id $job.Id
271262 WaitForJobStatus - Id $job.Id - Status " Suspended"
272263 $automationAccount | Resume-AzureAutomationJob - Id $job.Id
273264 WaitForJobStatus - Id $job.Id - Status " Completed"
274265
275266 # Remove runbook
276- Remove-AzureAutomationRunbook - AutomationAccountName $accountName - Id $runbook.Id - Force
267+ Remove-AzureAutomationRunbook - AutomationAccountName $accountName - Name $runbook.Name - Force
277268 Assert-Throws {Get-AzureAutomationRunbook $accountName - Name $runbook.Name }
278269}
279270
@@ -319,31 +310,34 @@ function Test-AutomationStartRunbookOnASchedule
319310
320311 $runbook = Register-AzureAutomationScheduledRunbook $accountName - Name $runbook.Name - ScheduleName $oneTimeScheName
321312 Assert-AreEqual $oneTimeScheName $runbook.ScheduleNames " The runbook should be associated with $oneTimeScheName "
322- $runbook = Register-AzureAutomationScheduledRunbook $accountName - Id $runbook.Id - ScheduleName $dailyScheName
313+ $runbook = Register-AzureAutomationScheduledRunbook $accountName - Name $runbook.Name - ScheduleName $dailyScheName
323314 Assert-True { $runbook.ScheduleNames -Contains $dailyScheName } " The runbook should be associated with $dailyScheName "
324315
325316 # waiting for seven minutes
326317 Wait-Seconds 420
327- $job = Get-AzureAutomationJob $accountName - RunbookId $runbook.Id | where {$_.ScheduleName -eq $oneTimeScheName }
318+ $job = Get-AzureAutomationJob $accountName - Name $runbook.Name | where {$_.ScheduleName -eq $oneTimeScheName }
319+ $jobSchedule = Get-AzureAutomationScheduledRunbook $accountName - RunbookName $runbook.Name - ScheduleName $oneTimeScheName
320+ Assert-AreEqual 1 $jobSchedule.Count
328321 Assert-AreEqual 1 $job.Count
329322 WaitForJobStatus - Id $job.Id - Status " Completed"
330323
331324 # Edit schedule
332325 $description = " Daily Schedule Description"
333- Set-AzureAutomationSchedule $accountName - Name $oneTimeScheName - Description $description
334- $dailySchedule = Get-AzureAutomationSchedule $accountName - Name $oneTimeScheName
326+ Set-AzureAutomationSchedule $accountName - Name $dailyScheName - Description $description
327+ $dailySchedule = Get-AzureAutomationSchedule $accountName - Name $dailyScheName
335328 Assert-AreEqual $description $dailySchedule.Description
336329
337- $runbook = Unregister-AzureAutomationScheduledRunbook $accountName - Name $runbook.Name - ScheduleName $dailyScheName
338- Assert-False {$runbook.ScheduleNames -Contains $dailyScheName } " The runbook shouldn't have an association with $dailyScheName "
330+ Unregister-AzureAutomationScheduledRunbook $accountName - Name $runbook.Name - ScheduleName $dailyScheName
331+ $jobSchedule = Get-AzureAutomationScheduledRunbook $accountName - RunbookName $runbook.Name - ScheduleName $dailyScheName
332+ Assert-Null $jobSchedule " The runbook shouldn't have an association with $dailyScheName "
339333
340334 # Remove runbook and schedule
341335 Remove-AzureAutomationSchedule $accountName - Name $oneTimeScheName - Force
342336 Assert-Throws {$automationAccount | Get-AzureAutomationSchedule - Name $oneTimeScheName }
343337 $automationAccount | Remove-AzureAutomationSchedule - Name $dailyScheName - Force
344338 Assert-Throws {$automationAccount | Get-AzureAutomationSchedule - Name $dailyScheName }
345- Remove-AzureAutomationRunbook $accountName - Id $runbook.Id - Force
346- Assert-Throws {Get-AzureAutomationRunbook $accountName - Id $runbook.Id }
339+ Remove-AzureAutomationRunbook $accountName - Name $runbook.Name - Force
340+ Assert-Throws {Get-AzureAutomationRunbook $accountName - Name $runbook.Name }
347341}
348342
349343<#
@@ -362,8 +356,8 @@ function Test-AutomationStartUnpublishedRunbook
362356 Assert-NotNull $runbook " runBook $runbookPath does not import successfully."
363357 Assert-NotNull $runbook.Tags " Tags of the runbook shouldn't be Null."
364358 Assert-NotNull $runbook.Description " Description of the runbook shouldn't be Null."
365- Assert-Throws {Start-AzureAutomationRunbook $accountName - Id $runbook.Id - Parameters $runbookParameters - PassThru - ErrorAction Stop}
359+ Assert-Throws {Start-AzureAutomationRunbook $accountName - Name $runbook.Name - Parameters $runbookParameters - PassThru - ErrorAction Stop}
366360
367- Remove-AzureAutomationRunbook $accountName - Id $runbook.Id - Force
368- Assert-Throws {Get-AzureAutomationRunbook $accountName - Id $runbook.Id - Parameters $runbookParameters - PassThru - ErrorAction Stop}
361+ Remove-AzureAutomationRunbook $accountName - Name $runbook.Name - Force
362+ Assert-Throws {Get-AzureAutomationRunbook $accountName - Name $runbook.Name - Parameters $runbookParameters - PassThru - ErrorAction Stop}
369363}
0 commit comments