Skip to content

Commit 3c54785

Browse files
authored
Merge pull request Azure#10175 from anusapan/get-subscription-iothub
[Bug Fixed] Cmdlet not returning some properties
2 parents 6eed678 + e691a31 commit 3c54785

File tree

5 files changed

+1260
-1180
lines changed

5 files changed

+1260
-1180
lines changed

src/IotHub/IotHub.Test/ScenarioTests/IotHubTests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function Test-AzureRmIotHubLifecycle
2929
$Location = Get-Location "Microsoft.Devices" "IotHub"
3030
$IotHubName = getAssetName
3131
$ResourceGroupName = getAssetName
32+
$SubscriptionId = '91d12660-3dec-467a-be2a-213b5544ddc0'
3233
$Sku = "B1"
3334
$namespaceName = getAssetName 'eventHub'
3435
$eventHubName = getAssetName
@@ -97,6 +98,8 @@ function Test-AzureRmIotHubLifecycle
9798

9899
Assert-True { $allIotHubsInResourceGroup.Count -eq 1 }
99100
Assert-True { $iotHub.Name -eq $IotHubName }
101+
Assert-True { $iotHub.Resourcegroup -eq $ResourceGroupName }
102+
Assert-True { $iotHub.Subscriptionid -eq $SubscriptionId }
100103
Assert-True { $iotHub.Properties.Routing.Routes.Count -eq 1}
101104
Assert-True { $iotHub.Properties.Routing.Routes[0].Name -eq "route"}
102105
Assert-True { $iotHub.Properties.Routing.Endpoints.EventHubs[0].Name -eq "eh1"}

src/IotHub/IotHub.Test/SessionRecords/Microsoft.Azure.Commands.IotHub.Test.ScenarioTests.IotHubTests/TestAzureIotHubLifeCycle.json

Lines changed: 1240 additions & 1179 deletions
Large diffs are not rendered by default.

src/IotHub/IotHub/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020
## Upcoming Release
2121
* Add new routing source: DigitalTwinChangeEvents
22+
* Minor bug fix: Get-AzIothub not returning subscriptionId
2223

2324
## Version 1.3.0
2425
* Add support to invoke failover for an IotHub to the geo-paired disaster recovery region.

src/IotHub/IotHub/Common/IotHubUtils.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,14 @@ public static string GetResourceGroupName(string Id)
299299
return m.Success ? m.Groups["rgname"].Value : null;
300300
}
301301

302+
public static string GetSubscriptionId(string Id)
303+
{
304+
if (string.IsNullOrEmpty(Id)) return null;
305+
Regex r = new Regex(@"(.*?)/subscriptions/(?<subscriptionid>\S+)/resourcegroups/(.*?)", RegexOptions.IgnoreCase);
306+
Match m = r.Match(Id);
307+
return m.Success ? m.Groups["subscriptionid"].Value : null;
308+
}
309+
302310
public static string GetIotHubName(string Id)
303311
{
304312
if (string.IsNullOrEmpty(Id)) return null;

src/IotHub/IotHub/Models/PSIotHub.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ public class PSIotHub
5454
/// The subscription identifier.
5555
/// </summary>
5656
[JsonProperty(PropertyName = "subscriptionid")]
57-
public string Subscriptionid { get; set; }
57+
public string Subscriptionid
58+
{
59+
get
60+
{
61+
return IotHubUtils.GetSubscriptionId(Id);
62+
}
63+
set { }
64+
}
5865

5966
/// <summary>
6067
/// The resource group name uniquely identifies the resource group

0 commit comments

Comments
 (0)