public override void ExecuteCmdlet() { string scope = this.GetDefaultScope(); string definitionId = null; if (this.IsParameterBound(x => x.Name)) { if (!this.Name.IsGuid()) { throw new ApplicationException("Name must be a valid GUID."); } definitionId = (new Guid(this.Name)).ToString(); } if (this.IsParameterBound(x => x.Scope)) { scope = this.Scope; } if (this.IsParameterBound(x => x.InputObject)) { if (!ManagedServicesUtility.TryParseDefinitionScopeFromResourceId(this.InputObject.Id, out scope) && string.IsNullOrWhiteSpace(scope)) { throw new ApplicationException($"Unable to parse the scope from [{this.InputObject.Id}]"); } if (string.IsNullOrWhiteSpace(this.InputObject.Name) || !this.InputObject.Name.IsGuid()) { throw new ApplicationException("Invalid registration definition name provided in input object."); } definitionId = this.InputObject.Name; } ConfirmAction(MyInvocation.InvocationName, $"/{scope}/providers/Microsoft.ManagedServices/registrationDefinitions/{definitionId}", () => { this.PSManagedServicesClient.RemoveRegistrationDefinition( scope: scope, registrationDefinitionId: definitionId); if (this.PassThru.IsPresent) { WriteObject(true); } }); }
public override void ExecuteCmdlet() { string scope = null; string assignmentId = null; if (this.IsParameterBound(x => x.Id)) { assignmentId = this.Id; scope = this.Scope ?? this.GetDefaultScope(); } else if (this.IsParameterBound(x => x.InputObject)) { assignmentId = this.InputObject.Id.GetResourceName(); if (!ManagedServicesUtility.TryParseAssignmentScopeFromResourceId(this.InputObject.Id, out scope)) { throw new ApplicationException($"Unable to parse the scope from [{this.InputObject.Id}]"); } } else if (this.IsParameterBound(x => x.ResourceId)) { assignmentId = this.ResourceId.GetResourceName(); if (!ManagedServicesUtility.TryParseAssignmentScopeFromResourceId(this.ResourceId, out scope)) { throw new ApplicationException($"Unable to parse the scope from [{this.ResourceId}]"); } } ConfirmAction(MyInvocation.InvocationName, $"/{scope}/providers/Microsoft.ManagedServices/registrationAssignments/{assignmentId}", () => { var result = this.PSManagedServicesClient.RemoveRegistrationAssignment( scope: scope, registrationAssignmentId: assignmentId); WriteObject(new PSRegistrationAssignment(result), true); }); }
public override void ExecuteCmdlet() { string scope = null; string definitionId = null; if (this.IsParameterBound(x => x.Id)) { scope = this.GetDefaultScope(); definitionId = this.Id; } else if (this.IsParameterBound(x => x.InputObject)) { definitionId = this.InputObject.Id.GetResourceName(); if (!ManagedServicesUtility.TryParseDefinitionScopeFromResourceId(this.InputObject.Id, out scope)) { throw new ApplicationException($"Unable to parse the scope from [{this.InputObject.Id}]"); } } else if (this.IsParameterBound(x => x.ResourceId)) { definitionId = this.ResourceId.GetResourceName(); if (!ManagedServicesUtility.TryParseDefinitionScopeFromResourceId(this.ResourceId, out scope)) { throw new ApplicationException($"Unable to parse the scope from [{this.ResourceId}]"); } } ConfirmAction(MyInvocation.InvocationName, $"/{scope}/providers/Microsoft.ManagedServices/registrationDefinitions{definitionId}", () => { this.PSManagedServicesClient.RemoveRegistrationDefinition( scope: scope, registrationDefinitionId: definitionId); }); }