This project is read-only.
The task library can be used directly from powershell by referencing the Utilities assembly.

Obviously Windows Azure Powershell comes with some cmdlets for interacting with Windows Azure Service Bus and you can use some of them to do tasks shown below, but the key thing you cant currently do with the cmdlets is the import/export.

The below example script shows you how you can undertake the following actions in powershell using the task library:

1. Modify the connection string and service bus namespace name to include the machine name so each developer can work against a service bus instance associated with their machine

2. Load the management certificate

3. Create the Service Bus Namespace

4. Create a SAS rule for a Developer which has the Manage/Listen/Send permission

5. Import the entities xml which was exported from Service Bus Explorer

Optional Extras:

Note at the bottom of the script ive also shown how you can delete all of the queues/topics/notification hubs which would be useful if you want to clean the namespace and re-import the xml

Script

$basePath = "{Folder Path to my assembly}"
[System.Reflection.Assembly]::LoadFrom("$basePath\AppFx.ServiceBus.Build.Utilities.dll")

$serviceBusNamespace = "AppFx-Test-@@LocalMachineName@@";
$sasKey = "{My SAS Key}";
$certPath = "$basePath\SBTesting.pfx";
$subscriptionId = "{My Azure Subscription ID}";
$certificatePassword = "{My PFX Password}";
$connectionString = "Endpoint=sb://{0}.servicebus.windows.net/;SharedAccessKeyName=Developer;SharedAccessKey={1}";
$importEntitiesPath = "$basePath\SB_Entities.xml";
$exportEntitiesPath = "Export_Entities.xml";
$sasRule = "Developer"

$modifiedServiceBusNamespace = [AppFx.ServiceBus.Build.Utilities.ServiceBusHelper]::ModifyServiceBusNamespaceName($serviceBusNamespace);
$formattedConnectionString = [System.String]::Format($connectionString, $serviceBusNamespace, $sasKey);
$modifiedConnectionString = [AppFx.ServiceBus.Build.Utilities.ServiceBusHelper]::ModifyServiceBusNamespaceName($formattedConnectionString);

Write-Host "Connection String " $modifiedConnectionString
Write-Host "Namespace " $modifiedServiceBusNamespace

$managementCert = [AppFx.ServiceBus.Build.Utilities.ManagementCertificateHelper]::LoadFromFile($certPath, $certificatePassword);

[AppFx.ServiceBus.Build.Utilities.ServiceBusHelper]::CreateNamespace($subscriptionId, $modifiedServiceBusNamespace, $managementCert, "North Europe");

[AppFx.ServiceBus.Build.Utilities.SharedAccessSecretHelper]::CreateFullSASRuleOnNamespaceRoot($subscriptionId, $managementCert, $modifiedServiceBusNamespace, $sasRule, $sasKey);

$serviceBusHelper = New-Object AppFx.ServiceBus.Build.Utilities.ServiceBusHelper($modifiedConnectionString)
$serviceBusHelper.ImportEntities($importEntitiesPath);
$serviceBusHelper.ExportEntities($exportEntitiesPath);
$serviceBusHelper.DeleteAllNamespaceEntities();

Last edited Nov 14, 2013 at 1:45 AM by michaelstephenson, version 3