Hi,
I am creating a stream analytic job from powershell and for that i am using a json file which provide all the details to create the job.
While creating input which is of type stream and getting data from Event Hub we need to provide like following : --
"properties": {
"ConsumerGroupName": "<ConsumerGroupName>",
"EventHubName": "<EventHubName>",
"ServiceBusNamespace": "<ServiceBusNamespace>",
"SharedAccessPolicyKey": "<SharedAccessPolicyKey>",
"SharedAccessPolicyName": "<SharedAccessPolicyName>"
}
now my script is also creating the EventHub and SAS policies if its not created.
So if i run the script first time, its creates the event hub and keys and update the details on json file.
$Key = [Microsoft.ServiceBus.Messaging.SharedAccessAuthorizationRule]::GenerateRandomKey()
$Rights = [Microsoft.ServiceBus.Messaging.AccessRights]::Listen, [Microsoft.ServiceBus.Messaging.AccessRights]::Send, [Microsoft.ServiceBus.Messaging.AccessRights]::Manage
$RightsColl = New-Object -TypeName System.Collections.Generic.List[Microsoft.ServiceBus.Messaging.AccessRights] (,[Microsoft.ServiceBus.Messaging.AccessRights[]]$Rights)
$AccessRule = New-Object -TypeName Microsoft.ServiceBus.Messaging.SharedAccessAuthorizationRule -ArgumentList "Manage", $Key, $RightsColl
$EventHubDescription.Authorization.Add($AccessRule)
$NamespaceManager.CreateEventHub($EventHubDescription);
Write-Host "The [$Path] event hub in the [$Namespace] namespace has been successfully created."
(Get-Content $path ) | Foreach-Object {
$_ -replace '<SharedAccessPolicyKey>', $Key `
-replace '<SharedAccessPolicyName>', 'Manage' `
} | Set-Content $path
But i want my script to be reusable so in scenarios where the event hub already exists , i want to retrieve the already existed policy key and update json file accordingly.
Any idea on how to achieve this.
I am looking for a solution using powershell but any other way is also using.