Azure context?

Good day, i am trying to use start-job as shown below.

My thinking is once the job completes i will have it do more, however when i run the command below i receive an error. The information i used as a guide was from

Link

Start-Job { param ($ctx) Get-AzureRmRecoveryServicesAsrJob -AzureRmContext $ctx} -Argumentlist (Get-AzureRmContext)

 

PS Microsoft.PowerShell.Core\FileSystem::\odcnafsvs001p\userm$\mcmahj> get-job | Receive-Job

Operation failed.

Unable to cast object of type ‘Microsoft.Azure.Commands.Profile.Models.PSAzureContext’ to type

‘Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureContext’.

  • CategoryInfo : CloseError: (:slight_smile: [Get-AzureRmRecoveryServicesAsrJob], Exception

  • FullyQualifiedErrorId : Microsoft.Azure.Commands.RecoveryServices.SiteRecovery.GetAzureRmR

ecoveryServicesAsrJob

  • PSComputerName : localhost

 

Thank you for any help.

What version of AzureRM.RecoveryServices.SiteRecovery do you have on your machine? I don’t see -AzureRmContext as an available parameter. At least not on 0.2.5 and it looks like the latest is 0.2.8.

I do see -DefaultProfile available, which is an alias for the AzureContext, but you shouldn’t have to pass that in as the job will run in the current context that you’re executing the Azure command from.

Thank you for the reply i am running 0.2.8AzureRM.RecoveryServices.SiteRecovery

If i try to leave out the context

using

Start-Job { Get-AzureRmRecoveryServicesAsrJob}

 

i receive the following error.

Operation failed.

ClientRequestId:

Vault Settings are missing. Please import Vault Settings and verify the same

  • CategoryInfo : CloseError: (:slight_smile: [Get-AzureRmRecoveryServicesAsrJob], Exception

  • FullyQualifiedErrorId : Microsoft.Azure.Commands.RecoveryServices.SiteRecovery.GetAzureRmRecoveryServicesAsrJob

  • PSComputerName : localhost

 

My understanding is the context needs passed through as a param because the scriptblock is not aware.

It’s possible. But I’m getting the same error with the command regardless if I’m running it as a job or if I’m running it on the console. It might be a bug with the command. Like if you run:

Get-AzureRmRecoveryServicesAsrJob -AzureRmContext (Get-AzureRmContext)

Do you still get the error?

Yep, as you said same error. Which begs the question how can i get the type the command is looking for?

Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureContext

instead of

Microsoft.Azure.Commands.Profile.Models.PSAzureContext