/// <summary> /// Populates the permissions on the resource. /// </summary> /// <param name="resource">The resource.</param> private async Task PopulatePermissions(PSObject resource) { try { var resourceId = resource.Properties["ResourceId"].Value.ToString(); var resourceCollectionId = resourceId + ResourceIdUtility .GetResourceCollectionId( subscriptionId: null, resourceGroupName: null, resourceType: null, extensionResourceType: "Microsoft.Authorization/permissions"); var apiVersion = await ApiVersionHelper .DetermineApiVersion( profile : this.Profile, providerNamespace : "Microsoft.Authorization", resourceType : "permissions", cancellationToken : this.CancellationToken.Value, pre : this.Pre) .ConfigureAwait(continueOnCapturedContext: false); var permissions = PaginatedResponseHelper.Enumerate( getFirstPage: () => this.GetPermissions(permissionCheckId: resourceCollectionId, apiVersion: apiVersion), getNextPage: nextLink => this.GetNextLink <Permission>(nextLink), cancellationToken: this.CancellationToken); resource.Properties.Add(new PSNoteProperty("Permissions", permissions)); } catch (Exception ex) { if (ex.IsFatal()) { throw; } ex = (ex is AggregateException) ? (ex as AggregateException).Flatten() : ex; this.errors.Add(new ErrorRecord(ex, "ErrorExpandingPermissions", ErrorCategory.CloseError, resource)); } }