public override void ExecuteCmdlet() { var subscription = SubscriptionId ?? DefaultContext.Subscription.Id; try { switch (ParameterSetName) { case ParameterSetNames.BlueprintAssignmentsBySubscription: foreach (var assignment in BlueprintClient.ListBlueprintAssignments(Utils.GetScopeForSubscription(subscription))) { WriteObject(assignment, true); } break; case ParameterSetNames.BlueprintAssignmentByName: WriteObject(BlueprintClient.GetBlueprintAssignment(Utils.GetScopeForSubscription(subscription), Name)); break; default: throw new PSInvalidOperationException(); } } catch (Exception ex) { WriteExceptionError(ex); } }
protected void ThrowIfAssignmentNotExist(string scope, string name) { PSBlueprintAssignment assignment = null; try { assignment = BlueprintClient.GetBlueprintAssignment(scope, name); } catch (Exception ex) { if (ex is CloudException cex && cex.Response.StatusCode != System.Net.HttpStatusCode.NotFound) { // if exception is for a reason other than .NotFound, pass it to the caller. throw; } } if (assignment == null) { throw new Exception(string.Format(Resources.AssignmentNotExist, name, scope)); } }