diff --git a/src/ResourceGraph/ResourceGraph/ChangeLog.md b/src/ResourceGraph/ResourceGraph/ChangeLog.md index b0c35744ab08..000c10217c54 100644 --- a/src/ResourceGraph/ResourceGraph/ChangeLog.md +++ b/src/ResourceGraph/ResourceGraph/ChangeLog.md @@ -18,6 +18,7 @@ - Additional information about change #1 --> ## Upcoming Release +* Fixed the output print issue for `Search-AzGraph`. Fixed the issue when Search-AzGraph fails when no subscriptions are stored in the context. ## Version 0.10.0 * Changed output of `Search-AzGraph` to PSResourceGraphResponse which wrapped previous output under Data property. diff --git a/src/ResourceGraph/ResourceGraph/Cmdlets/SearchAzureRmGraph.cs b/src/ResourceGraph/ResourceGraph/Cmdlets/SearchAzureRmGraph.cs index 674d722d56da..19ef4762a0d1 100644 --- a/src/ResourceGraph/ResourceGraph/Cmdlets/SearchAzureRmGraph.cs +++ b/src/ResourceGraph/ResourceGraph/Cmdlets/SearchAzureRmGraph.cs @@ -150,7 +150,7 @@ public override void ExecuteCmdlet() IList subscriptions = null; if (managementGroups == null) { - subscriptions = this.GetSubscriptions().ToList(); + subscriptions = this.GetSubscriptions()?.ToList(); if (subscriptions != null && subscriptions.Count > SubscriptionLimit) { subscriptions = subscriptions.Take(SubscriptionLimit).ToList(); @@ -262,7 +262,7 @@ private IEnumerable GetSubscriptions() } var accountSubscriptions = this.DefaultContext.Account.GetSubscriptions(); - if (accountSubscriptions.Length > 0) + if (accountSubscriptions?.Length > 0) { return accountSubscriptions; } diff --git a/src/ResourceGraph/ResourceGraph/help/Search-AzGraph.md b/src/ResourceGraph/ResourceGraph/help/Search-AzGraph.md index cd4d771d943f..fa70b00c36bd 100644 --- a/src/ResourceGraph/ResourceGraph/help/Search-AzGraph.md +++ b/src/ResourceGraph/ResourceGraph/help/Search-AzGraph.md @@ -64,7 +64,8 @@ A complex query on resources featuring field selection, filtering and summarizin ### Example 3 ```powershell -PS C:\> Search-AzGraph -Query 'project id, name' -SkipToken 'skiptokenvaluefromthepreviousquery==' +PS C:\> $response = (Search-AzGraph -Query 'project id, name' -First 1000) +PS C:\> Search-AzGraph -Query 'project id, name' -SkipToken $response.SkipToken id : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/Service-INT-b/providers/Microsoft.Compute/virtualMachineScaleSets/nt2 @@ -74,7 +75,7 @@ id : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/ name : egtopic-2 ``` -A query with the skip token passed from the previous query results +A query with the skip token passed from the previous query results. Please note that keeping id in the results is mandatory to get back a skip token. ### Example 4 ```powershell