public override void ExecuteCmdlet() { switch (ParameterSetName) { case ParameterSetNames.SubscriptionScope: int fetchedItems = 0; string nextLink = null; var assessments = SecurityCenterClient.SubAssessments.ListAllWithHttpMessagesAsync(AssessedResourceId ?? $"subscriptions/{DefaultContext.Subscription.Id}").GetAwaiter().GetResult().Body; var psAssessments = assessments.ConvertToPSType(); WriteObject(psAssessments, enumerateCollection: true); fetchedItems += psAssessments.Count; nextLink = assessments?.NextPageLink; while (!string.IsNullOrWhiteSpace(nextLink) && fetchedItems < MaxItemsToFetch) { assessments = SecurityCenterClient.SubAssessments.ListAllNextWithHttpMessagesAsync(nextLink).GetAwaiter().GetResult().Body; psAssessments = assessments.ConvertToPSType(); WriteObject(psAssessments, enumerateCollection: true); fetchedItems += psAssessments.Count; nextLink = assessments?.NextPageLink; } break; case ParameterSetNames.ResourceIdScope: fetchedItems = 0; nextLink = null; assessments = SecurityCenterClient.SubAssessments.ListWithHttpMessagesAsync(AssessedResourceId ?? $"subscriptions/{DefaultContext.Subscription.Id}", AssessmentName).GetAwaiter().GetResult().Body; psAssessments = assessments.ConvertToPSType(); WriteObject(psAssessments, enumerateCollection: true); fetchedItems += psAssessments.Count; nextLink = assessments?.NextPageLink; while (!string.IsNullOrWhiteSpace(nextLink) && fetchedItems < MaxItemsToFetch) { assessments = SecurityCenterClient.SubAssessments.ListNextWithHttpMessagesAsync(nextLink).GetAwaiter().GetResult().Body; psAssessments = assessments.ConvertToPSType(); WriteObject(psAssessments, enumerateCollection: true); fetchedItems += psAssessments.Count; nextLink = assessments?.NextPageLink; } break; case ParameterSetNames.SubscriptionLevelResource: case ParameterSetNames.ResourceIdLevelResource: var assessment = SecurityCenterClient.SubAssessments.GetWithHttpMessagesAsync(AssessedResourceId ?? $"subscriptions/{DefaultContext.Subscription.Id}", AssessmentName, Name).GetAwaiter().GetResult().Body; WriteObject(assessment.ConvertToPSType(), enumerateCollection: false); break; case ParameterSetNames.ResourceId: assessment = SecurityCenterClient.SubAssessments.GetWithHttpMessagesAsync(AzureIdUtilities.GetExtendedResourceId(ResourceId), AzureIdUtilities.GetAssessmentResourceName(ResourceId), AzureIdUtilities.GetResourceName(ResourceId)).GetAwaiter().GetResult().Body; WriteObject(assessment.ConvertToPSType(), enumerateCollection: false); break; default: throw new PSInvalidOperationException(); } }