+ +``` +# +# Module manifest for module 'Az.MyService' +# +# Generated by: Microsoft Corporation +# +# Generated on: 3/11/2019 +# + +@{ + +# Script module or binary module file associated with this manifest. +# RootModule = '' + +# Version number of this module. +ModuleVersion = '0.1.0' + +# Supported PSEditions +CompatiblePSEditions = 'Core', 'Desktop' + +# ID used to uniquely identify this module +GUID = '{{ GENERATE A RANDOM GUID TO USE HERE }}' + +# Author of this module +Author = 'Microsoft Corporation' + +# Company or vendor of this module +CompanyName = 'Microsoft Corporation' + +# Copyright statement for this module +Copyright = 'Microsoft Corporation. All rights reserved.' + +# Description of the functionality provided by this module +Description = '' + +# Minimum version of the PowerShell engine required by this module +PowerShellVersion = '5.1' + +# Name of the PowerShell host required by this module +# PowerShellHostName = '' + +# Minimum version of the PowerShell host required by this module +# PowerShellHostVersion = '' + +# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +DotNetFrameworkVersion = '4.7.2' + +# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# CLRVersion = '' + +# Processor architecture (None, X86, Amd64) required by this module +# ProcessorArchitecture = '' + +# Modules that must be imported into the global environment prior to importing this module +RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '1.4.0'; }) + +# Assemblies that must be loaded prior to importing this module +RequiredAssemblies = '.\Microsoft.Azure.Management.MyService.dll' + +# Script files (.ps1) that are run in the caller's environment prior to importing this module. +# ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +# TypesToProcess = @() + +# Format files (.ps1xml) to be loaded when importing this module +FormatsToProcess = '.\MyService.format.ps1xml' + +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +NestedModules = '.\Microsoft.Azure.PowerShell.Cmdlets.MyService.dll' + +# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. +FunctionsToExport = @() + +# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. +CmdletsToExport = 'Get-AzMyServiceResource', 'New-AzMyServiceResource', + 'Remove-AzMyServiceResource', 'Update-AzMyServiceResource' + +# Variables to export from this module +# VariablesToExport = @() + +# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. +AliasesToExport = @() + +# DSC resources to export from this module +# DscResourcesToExport = @() + +# List of all modules packaged with this module +# ModuleList = @() + +# List of all files packaged with this module +# FileList = @() + +# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. +PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + Tags = 'Azure','ResourceManager','ARM' + + # A URL to the license for this module. + LicenseUri = 'https://aka.ms/azps-license' + + # A URL to the main website for this project. + ProjectUri = 'https://github.com/Azure/azure-powershell' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + ReleaseNotes = '' + + # Prerelease string of this module + # Prerelease = '' + + # Flag to indicate whether the module requires explicit user acceptance for install/update + # RequireLicenseAcceptance = $false + + # External dependent modules of this module + # ExternalModuleDependencies = @() + + } # End of PSData hashtable + + } # End of PrivateData hashtable + +# HelpInfo URI of this module +# HelpInfoURI = '' + +# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. +# DefaultCommandPrefix = '' + +} +``` + +
+- -```cs -namespace Microsoft.Azure.Commands.Foo -{ - [Cmdlet(VerbsCommon.Get, "AzFoo", DefaultParameterSetName = ListParameterSet), OutputType(typeof(PSFoo))] - public class GetFooCommand : FooBaseCmdlet - { - private const string ListParameterSet = "ListParameterSet"; - private const string GetByNameParameterSet = "GetByNameParameterSet";" - private const string GetByResourceIdParameterSet = "GetByResourceIdParameterSet"; - - [Parameter(Mandatory = false, ParameterSetName = ListParameterSet)] - [Parameter(Mandatory = true, ParameterSetName = GetByNameParameterSet)] - [ResourceGroupCompleter] - [ValidateNotNullOrEmpty] - public string ResourceGroupName { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = GetByNameParameterSet)] - [ValidateNotNullOrEmpty] - public string Name { get; set; } - - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = GetByResourceIdParameterSet )] - [ValidateNotNullOrEmpty] - public string ResourceId { get; set; } - - public override void ExecuteCmdlet() - { - if (this.IsParameterBound(c => c.ResourceId)) - { - var resourceIdentifier = new ResourceIdentifier(this.ResourceId); - this.ResourceGroupName = resourceIdentifier.ResourceGroupName; - this.Name = resourceIdentifier.ResourceName; - } - - if (!string.IsNullOrEmpty(this.Name)) - { - var result = new PSFoo(this.MySDKClient.Foo.Get(this.ResourceGroupName, this.Name)); - WriteObject(result); - } - else if (!string.IsNullOrEmpty(this.ResourceGroupName)) - { - var result = this.MySDKClient.Foo.ListByResourceGroup(this.ResourceGroupName).Select(f => new PSFoo(f)); - WriteObject(result, true); - } - else - { - var result = this.MySDKClient.Foo.List().Select(f => new PSFoo(f)); - WriteObject(result, true); - } - } - } -} -``` - -
-- -```cs -namespace Microsoft.Azure.Commands.Foo -{ - [Cmdlet(VerbsCommon.New, "AzFoo", DefaultParameterSetName = CreateParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSFoo))] - public class NewFooCommand : FooBaseCmdlet - { - private const string CreateParameterSet = "CreateParameterSet"; - - [Parameter(Mandatory = true, ParameterSetName = CreateParameterSet)] - [ResourceGroupCompleter] - [ValidateNotNullOrEmpty] - public string ResourceGroupName { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = CreateParameterSet)] - [ValidateNotNullOrEmpty] - public string Name { get; set; } - - [Parameter(Mandatory = false, ParameterSetName = CreateParameterSet)] - public Type1 Property1 { get; set; } - - [Parameter(Mandatory = false, ParameterSetName = CreateParameterSet)] - public Type2 Property2 { get; set; } - - // Excluding other property parameters - - public override void ExecuteCmdlet() - { - Foo existingFoo = null; - try - { - existingFoo = this.MySDKClient.Foo.Get(this.ResourceGroupName, this.Name); - } - catch - { - existingFoo = null; - } - - if (existingFoo != null) - { - throw new Exception(string.Format("A Foo with name '{0}' in resource group '{1}' already exists. Please use Set/Update-AzFoo to update an existing Foo.", this.Name, this.ResourceGroupName)); - } - - existingFoo = new Foo() - { - Name = this.Name, - ResourceGroupName = this.ResourceGroupName, - Property1 = this.Property1, - Property2 = this.Property2, - ... - } - - if (this.ShouldProcess(this.Name, string.Format("Creating a new Foo in resource group '{0}' with name '{1}'.", this.ResourceGroupName, this.Name)) - { - var result = new PSFoo(this.MySDKClient.Foo.CreateOrUpdate(existingFoo)); - WriteObject(result); - } - } - } -} -``` - -
-- -```cs -namespace Microsoft.Azure.Commands.Foo -{ - [Cmdlet(VerbsCommon.Remove, "AzFoo", DefaultParameterSetName = DeleteByNameParameterSet, SupportsShouldProcess = true), OutputType(typeof(bool))] - public class RemoveFooCommand : FooBaseCmdlet - { - private const string DeleteByNameParameterSet = "DeleteByNameParameterSet"; - private const string DeleteByInputObjectParameterSet = "DeleteByInputObjectParameterSet"; - private const string DeleteByResourceIdParameterSet = "DeleteByResourceIdParameterSet"; - - [Parameter(Mandatory = true, ParameterSetName = DeleteByNameParameterSet)] - [ResourceGroupCompleter] - [ValidateNotNullOrEmpty] - public string ResourceGroupName { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = DeleteByNameParameterSet)] - [ValidateNotNullOrEmpty] - public string Name { get; set; } - - [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = DeleteByInputObjectParameterSet)] - [ValidateNotNull] - public PSFoo InputObject { get; set; } - - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = DeleteByResourceIdParameterSet)] - [ValidateNotNullOrEmpty] - public string ResourceId { get; set; } - - [Parameter(Mandatory = false)] - public SwitchParameter PassThru { get; set; } - - public override void ExecuteCmdlet() - { - if (this.IsParameterBound(c => c.InputObject)) - { - this.ResourceGroupName = this.InputObject.ResourceGroupName; - this.Name = this.InputObject.Name; - } - - if (this.IsParameterBound(c => c.ResourceId)) - { - var resourceIdentifier = new ResourceIdentifier(this.ResourceId); - this.ResourceGroupName = resourceIdentifier.ResourceGroupName; - this.Name = resourceIdentifier.ResourceName; - } - - if (this.ShouldProcess(this.Name, string.Format("Deleting Foo '{0}' in resource group {0}", this.Name, this.ResourceGroupName))) - { - this.MySDKClient.Foo.Delete(this.ResourceGroupName, this.Name); - if (this.IsPassThru.IsPresent) - { - WriteObject(true); - } - } - } - } -} -``` - -
-- -```cs -namespace Microsoft.Azure.Commands.Foo -{ - [Cmdlet(VerbsCommon.Set, "AzFoo", DefaultParameterSet = SetByNameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSFoo))] - public class SetFooCommand : FooBaseCmdlet - { - private const string SetByNameParameterSet = "SetByNameParameterSet"; - private const string SetByInputObjectParameterSet = "SetByInputObjectParameterSet"; - private const string SetByResourceIdParameterSet = "SetByResourceIdParameterSet"; - - [Parameter(Mandatory = true, ParameterSetName = SetByNameParameterSet)] - [ResourceGroupCompleter] - [ValidateNotNullOrEmpty] - public string ResourceGroupName { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = SetByNameParameterSet)] - [ValidateNotNullOrEmpty] - public string Name { get; set; } - - [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = SetByInputObjectParameterSet)] - [ValidateNotNull] - public PSFoo InputObject { get; set; } - - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = SetByResourceIdParameterSet)] - [ValidateNotNullOrEmpty] - public string ResourceId { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = SetByNameParameterSet)] - [Parameter(Mandatory = true, ParameterSetName = SetByResourceIdParameterSet)] - [Parameter(Mandatory = false, ParameterSetName = SetByInputObjectParameterSet)] - public Type1 Property1 { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = SetByNameParameterSet)] - [Parameter(Mandatory = true, ParameterSetName = SetByResourceIdParameterSet)] - [Parameter(Mandatory = false, ParameterSetName = SetByInputObjectParameterSet)] - public Type2 Property2 { get; set; } - - // Excluding other property parameters - - public override void ExecuteCmdlet() - { - if (this.IsParameterBound(c => c.InputObject)) - { - this.ResourceGroupName = this.InputObject.ResourceGroupName; - this.Name = this.InputObject.Name; - this.Property1 = this.IsParameterBound(c => c.Property1) ? this.Property1 : this.InputObject.Property1; - this.Property2 = this.IsParameterBound(c => c.Property2) ? this.Property2 : this.InputObject.Property2; - ... - } - - if (this.IsParameterBound(c => c.ResourceId)) - { - var resourceIdentifier = new ResourceIdentifier(this.ResourceId); - this.ResourceGroupName = resourceIdentifier.ResourceGroupName; - this.Name = resourceIdentifier.ResourceName; - } - - Foo foo = null; - try - { - foo = this.MySDKClient.Foo.Get(this.ResourceGroupName, this.Name); - } - catch - { - foo = null; - } - - if (foo == null) - { - throw new Exception(string.Format("A Foo with name '{0}' in resource group '{1}' does not exist. Please use New-AzFoo to create a Foo with these properties.", this.Name, this.ResourceGroupName)); - } - - foo.Property1 = this.Property1; - foo.Property2 = this.Property2; - ... - - if (this.ShouldProcess(this.Name, string.Format("Updating Foo '{0}' in resource group '{1}'.", this.Name, this.ResourceGroupName))) - { - var result = new PSFoo(this.MySDKClient.Foo.Update(this.ResourceGroupName, this.Name, foo) - WriteObject(result); - } - } - } -} -``` - -
-- -```cs -namespace Microsoft.Azure.Commands.Foo -{ - [Cmdlet(VerbsData.Update, "AzFoo", DefaultParameterSet = UpdateByNameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSFoo))] - public class UpdateFooCommand : FooBaseCmdlet - { - private const string UpdateByNameParameterSet = "UpdateByNameParameterSet"; - private const string UpdateByInputObjectParameterSet = "UpdateByInputObjectParameterSet"; - private const string UpdateByResourceIdParameterSet = "UpdateByResourceIdParameterSet"; - - [Parameter(Mandatory = true, ParameterSetName = UpdateByNameParameterSet)] - [ResourceGroupCompleter] - [ValidateNotNullOrEmpty] - public string ResourceGroupName { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = UpdateByNameParameterSet)] - [ValidateNotNullOrEmpty] - public string Name { get; set; } - - [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = UpdateByInputObjectParameterSet)] - [ValidateNotNull] - public PSFoo InputObject { get; set; } - - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = UpdateByResourceIdParameterSet)] - [ValidateNotNullOrEmpty] - public string ResourceId { get; set; } - - [Parameter(Mandatory = false)] - public Type1 Property1 { get; set; } - - [Parameter(Mandatory = false)] - public Type2 Property2 { get; set; } - - // Excluding other property parameters - - public override void ExecuteCmdlet() - { - if (this.IsParameterBound(c => c.InputObject)) - { - this.ResourceGroupName = this.InputObject.ResourceGroupName; - this.Name = this.InputObject.Name; - } - - if (this.IsParameterBound(c => c.ResourceId)) - { - var resourceIdentifier = new ResourceIdentifier(this.ResourceId); - this.ResourceGroupName = resourceIdentifier.ResourceGroupName; - this.Name = resourceIdentifier.ResourceName; - } - - Foo foo = null; - try - { - foo = this.MySDKClient.Foo.Get(this.ResourceGroupName, this.Name); - } - catch - { - foo = null; - } - - if (foo == null) - { - throw new Exception(string.Format("A Foo with name '{0}' in resource group '{1}' does not exist. Please use New-AzFoo to create a Foo with these properties.", this.Name, this.ResourceGroupName)); - } - - foo.Property1 = this.IsParameterBound(c => c.Property1) ? this.Property1 : foo.Property1; - foo.Property2 = this.IsParameterBound(c => c.Property2) ? this.Property2 : foo.Property2; - ... - - if (this.ShouldProcess(this.Name, string.Format("Updating Foo '{0}' in resource group '{1}'.", this.Name, this.ResourceGroupName))) - { - var result = new PSFoo(this.MySDKClient.Foo.Update(this.ResourceGroupName, this.Name, foo) - WriteObject(result); - } - } - } -} -``` - -
-- -```cs -namespace Microsoft.Azure.Commands.Foo -{ - [Cmdlet(VerbsCommon.Get, "AzChildFoo", DefaultParameterSetName = GetByNameParameterSet), OutputType(typeof(PSChildFoo))] - public class GetChildFooCommand : FooBaseCmdlet - { - private const string GetByNameParameterSet = "GetByNameParameterSet"; - private const string GetByParentObjectParameterSet = "GetByParentObjectParameterSet"; - private const string GetByResourceIdParameterSet = "GetByResourceIdParameterSet"; - - [Parameter(Mandatory = true, ParameterSetName = GetByNameParameterSet)] - [ResourceGroupCompleter] - [ValidateNotNullOrEmpty] - public string ResourceGroupName { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = GetByNameParameterSet)] - [ValidateNotNullOrEmpty] - public string FooName { get; set; } - - [Parameter(Mandatory = false, ParameterSetName = GetByNameParameterSet)] - [Parameter(Mandatory = false, ParameterSetName = GetByParentObjectParameterSet)] - [ValidateNotNullOrEmpty] - public string Name { get; set; } - - [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = GetByParentObjectParameterSet)] - [ValidateNotNull] - public PSFoo FooObject { get; set; } - - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = GetByResourceIdParameterSet)] - [ValidateNotNullOrEmpty] - public string ResourceId { get; set; } - - public override void ExecuteCmdlet() - { - if (this.IsParameterBound(c => c.ResourceId)) - { - var resourceIdentifier = new ResourceIdentifier(this.ResourceId); - this.ResourceGroupName = resourceIdentifier.ResourceGroupName; - this.FooName = resourceIdentifier.ParentResource - this.Name = resourceIdentifier.ResourceName; - } - - if (this.IsParameterBound(c => c.FooObject)) - { - this.ResourceGroupName = this.FooObject.ResourceGroupName; - this.FooName = this.FooObject.Name; - } - - if (!string.IsNullOrEmpty(this.Name)) - { - var result = new PSChildFoo(this.MySDKClient.ChildFoo.Get(this.ResourceGroupName, this.FooName, this.Name)); - WriteObject(result); - } - else - { - var result = this.MySDKClient.ChildFoo.ListByFoo(this.ResourceGroupName, this.FooName).Select(f => new PSChildFoo(f)); - WriteObject(result, true); - } - } - } -} -``` - -
-- -```cs -namespace Microsoft.Azure.Commands.Foo -{ - [Cmdlet(VerbsCommon.New, "AzChildFoo", DefaultParameterSetName = CreateByNameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSChildFoo))] - public class NewChildFooCommand : FooBaseCmdlet - { - private const string CreateByNameParameterSet = "CreateByNameParameterSet"; - private const string CreateByParentObjectParameterSet = "CreateByParentObjectParameterSet"; - - [Parameter(Mandatory = true, ParameterSetName = CreateByNameParameterSet)] - [ResourceGroupCompleter] - [ValidateNotNullOrEmpty] - public string ResourceGroupName { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = CreateByNameParameterSet)] - [ValidateNotNullOrEmpty] - public string FooName { get; set; } - - [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = CreateByParentObjectParameterSet)] - [ValidateNotNull] - public PSFoo FooObject { get; set; } - - [Parameter(Mandatory = true)] - [ValidateNotNullOrEmpty] - public string Name { get; set; } - - [Parameter(Mandatory = false)] - public Type1 Property1 { get; set; } - - [Parameter(Mandatory = false)] - public Type2 Property2 { get; set; } - - // Excluding other property parameters - - public override void ExecuteCmdlet() - { - if (this.IsParameterBound(c => c.FooObject)) - { - this.ResourceGroupName = this.FooObject.ResourceGroupName; - this.FooName = this.FooObject.FooName; - } - - ChildFoo existingFoo = null; - try - { - existingChildFoo = this.MySDKClient.ChildFoo.Get(this.ResourceGroupName, this.FooName, this.Name); - } - catch - { - existingChildFoo = null; - } - - if (existingChildFoo != null) - { - throw new Exception(string.Format("A ChildFoo with name '{0}' in resource group '{1}' under parent Foo '{2}' already exists. Please use Set/Update-AzChildFoo to update an existing ChildFoo.", this.Name, this.ResourceGroupName, this.FooName)); - } - - existingChildFoo = new ChildFoo() - { - Name = this.Name, - FooName = this.FooName, - ResourceGroupName = this.ResourceGroupName, - Property1 = this.Property1, - Property2 = this.Property2, - ... - } - - if (this.ShouldProcess(this.Name, string.Format("Creating a new ChildFoo in resource group '{0}' under parent Foo '{1}' with name '{2}'.", this.ResourceGroupName, this.FooName, this.Name)) - { - var result = new PSChildFoo(this.MySDKClient.ChildFoo.CreateOrUpdate(existingChildFoo)); - WriteObject(result); - } - } - } -} -``` - -
-- -```cs -namespace Microsoft.Azure.Commands.Foo -{ - [Cmdlet(VerbsCommon.Remove, "AzChildFoo", DefaultParameterSetName = DeleteByNameParameterSet, SupportsShouldProcess = true), OutputType(typeof(bool))] - public class RemoveChildFooCommand : FooBaseCmdlet - { - private const string DeleteByNameParameterSet = "DeleteByNameParameterSet"; - private const string DeleteByParentObjectParameterSet = "DeleteByParentObjectParameterSet"; - private const string DeleteByInputObjectParameterSet = "DeleteByInputObjectParameterSet"; - private const string DeleteByResourceIdParameterSet = "DeleteByResourceIdParameterSet"; - - [Parameter(Mandatory = true, ParameterSetName = DeleteByNameParameterSet)] - [ResourceGroupCompleter] - [ValidateNotNullOrEmpty] - public string ResourceGroupName { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = DeleteByNameParameterSet)] - [ValidateNotNullOrEmpty] - public string FooName { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = DeleteByNameParameterSet)] - [Parameter(Mandatory = true, ParameterSetName = DeleteByParentObjectParameterSet)] - [ValidateNotNullOrEmpty] - public string Name { get; set; } - - [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = DeleteByParentObjectParameterSet)] - [ValidateNotNull] - public PSFoo FooObject { get; set; } - - [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = DeleteByInputObjectParameterSet)] - [ValidateNotNull] - public PSChildFoo InputObject { get; set; } - - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = DeleteByResourceIdParameterSet)] - [ValidateNotNullOrEmpty] - public string ResourceId { get; set; } - - [Parameter(Mandatory = false)] - public SwitchParameter PassThru { get; set; } - - public override void ExecuteCmdlet() - { - if (this.IsParameterBound(c => c.FooObject)) - { - this.ResourceGroupName = this.FooObject.ResourceGroupName; - this.FooName = this.FooObject.Name; - } - - if (this.IsParameterBound(c => c.InputObject)) - { - this.ResourceGroupName = this.InputObject.ResourceGroupName; - this.FooName = this.InputObject.FooName; - this.Name = this.InputObject.Name; - } - - if (this.IsParameterBound(c => c.ResourceId)) - { - var resourceIdentifier = new ResourceIdentifier(this.ResourceId); - this.ResourceGroupName = resourceIdentifier.ResourceGroupName; - this.FooName = resourceIdentifier.ParentResource; - this.Name = resourceIdentifier.ResourceName; - } - - if (this.ShouldProcess(this.Name, string.Format("Deleting ChildFoo '{0}' in resource group '{1}' under parent Foo '{2}'.", this.Name, this.ResourceGroupName, this.FooName))) - { - this.MySDKClient.ChildFoo.Delete(this.ResourceGroupName, this.FooName, this.Name); - if (this.IsPassThru.IsPresent) - { - WriteObject(true); - } - } - } - } -} -``` - -
-- -```cs -namespace Microsoft.Azure.Commands.Foo -{ - [Cmdlet(VerbsCommon.Set, "AzChildFoo", DefaultParameterSet = SetByNameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSChildFoo))] - public class SetChildFooCommand : FooBaseCmdlet - { - private const string SetByNameParameterSet = "SetByNameParameterSet"; - private const string SetByParentObjectParameterSet = "SetByParentObjectParameterSet"; - private const string SetByInputObjectParameterSet = "SetByInputObjectParameterSet"; - private const string SetByResourceIdParameterSet = "SetByResourceIdParameterSet"; - - [Parameter(Mandatory = true, ParameterSetName = SetByNameParameterSet)] - [ResourceGroupCompleter] - [ValidateNotNullOrEmpty] - public string ResourceGroupName { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = SetByNameParameterSet) - [ValidateNotNullOrEmpty] - public string FooName { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = SetByNameParameterSet)] - [Parameter(Mandatory = true, ParameterSetName = SetByParentObjectParameterSet)] - [ValidateNotNullOrEmpty] - public string Name { get; set; } - - [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = SetByParentObjectParameterSet)] - [ValidateNotNull] - public PSFoo FooObject { get; set; } - - [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = SetByInputObjectParameterSet)] - [ValidateNotNull] - public PSChildFoo InputObject { get; set; } - - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = SetByResourceIdParameterSet)] - [ValidateNotNullOrEmpty] - public string ResourceId { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = SetByNameParameterSet)] - [Parameter(Mandatory = true, ParameterSetName = SetByParentObjectParameterSet)] - [Parameter(Mandatory = true, ParameterSetName = SetByResourceIdParameterSet)] - [Parameter(Mandatory = false, ParameterSetName = SetByInputObjectParameterSet)] - public Type1 Property1 { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = SetByNameParameterSet)] - [Parameter(Mandatory = true, ParameterSetName = SetByParentObjectParameterSet)] - [Parameter(Mandatory = true, ParameterSetName = SetByResourceIdParameterSet)] - [Parameter(Mandatory = false, ParameterSetName = SetByInputObjectParameterSet)] - public Type2 Property2 { get; set; } - - // Excluding other property parameters - - public override void ExecuteCmdlet() - { - if (this.IsParameterBound(c => c.FooObject)) - { - this.ResourceGroupName = this.FooObject.ResourceGroupName; - this.FooName = this.FooObject.Name; - } - - if (this.IsParameterBound(c => c.InputObject)) - { - this.ResourceGroupName = this.InputObject.ResourceGroupName; - this.FooName = this.InputObject.FooName; - this.Name = this.InputObject.Name; - this.Property1 = this.IsParameterBound(c => c.Property1) ? this.Property1 : this.InputObject.Property1; - this.Property2 = this.IsParameterBound(c => c.Property2) ? this.Property2 : this.InputObject.Property2; - ... - } - - if (this.IsParameterBound(c => c.ResourceId)) - { - var resourceIdentifier = new ResourceIdentifier(this.ResourceId); - this.ResourceGroupName = resourceIdentifier.ResourceGroupName; - this.FooName = resourceIdentifier.ParentResource; - this.Name = resourceIdentifier.ResourceName; - } - - ChildFoo childFoo = null; - try - { - childFoo = this.MySDKClient.ChildFoo.Get(this.ResourceGroupName, this.FooName, this.Name); - } - catch - { - childFoo = null; - } - - if (childFoo == null) - { - throw new Exception(string.Format("A ChildFoo with name '{0}' in resource group '{1}' under parent Foo '{2}' does not exist. Please use New-AzChildFoo to create a ChildFoo with these properties.", this.Name, this.ResourceGroupName, this.FooName)); - } - - childFoo.Property1 = this.Property1; - childFoo.Property2 = this.Property2; - ... - - if (this.ShouldProcess(this.Name, string.Format("Updating Foo '{0}' in resource group '{1}' under parent Foo '{2}'.", this.Name, this.ResourceGroupName, this.FooName))) - { - var result = new PSChildFoo(this.MySDKClient.ChildFoo.Update(this.ResourceGroupName, this.FooName, this.Name, childFoo) - WriteObject(result); - } - } - } -} -``` - -
-- -```cs -namespace Microsoft.Azure.Commands.Foo -{ - [Cmdlet(VerbsData.Update, "AzChildFoo", DefaultParameterSet = UpdateByNameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSChildFoo))] - public class UpdateChildFooCommand : FooBaseCmdlet - { - private const string UpdateByNameParameterSet = "UpdateByNameParameterSet"; - private const string UpdateByParentObjectParameterSet = "UpdateByParentObjectParameterSet"; - private const string UpdateByInputObjectParameterSet = "UpdateByInputObjectParameterSet"; - private const string UpdateByResourceIdParameterSet = "UpdateByResourceIdParameterSet"; - - [Parameter(Mandatory = true, ParameterSetName = UpdateByNameParameterSet)] - [ResourceGroupCompleter] - [ValidateNotNullOrEmpty] - public string ResourceGroupName { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = UpdateByNameParameterSet)] - [ValidateNotNullOrEmpty] - public string FooName { get; set; } - - [Parameter(Mandatory = true, ParameterSetName = UpdateByNameParameterSet)] - [Parameter(Mandatory = true, ParameterSetName = UpdateByParentObjectParameterSet)] - [ValidateNotNullOrEmpty] - public string Name { get; set; } - - [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = UpdateByParentObjectParameterSet)] - [ValidateNotNull] - public PSFoo FooObject { get; set; } - - [Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = UpdateByInputObjectParameterSet)] - [ValidateNotNull] - public PSFoo InputObject { get; set; } - - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = UpdateByResourceIdParameterSet)] - [ValidateNotNullOrEmpty] - public string ResourceId { get; set; } - - [Parameter(Mandatory = false)] - public Type1 Property1 { get; set; } - - [Parameter(Mandatory = false)] - public Type2 Property2 { get; set; } - - // Excluding other property parameters - - public override void ExecuteCmdlet() - { - if (this.IsParameterBound(c => c.FooObject)) - { - this.ResourceGroupName = this.FooObject.ResourceGroupName; - this.FooName = this.FooObject.Name; - } - - if (this.IsParameterBound(c => c.InputObject)) - { - this.ResourceGroupName = this.InputObject.ResourceGroupName; - this.FooName = this.InputObject.FooName; - this.Name = this.InputObject.Name; - } - - if (this.IsParameterBound(c => c.ResourceId)) - { - var resourceIdentifier = new ResourceIdentifier(this.ResourceId); - this.ResourceGroupName = resourceIdentifier.ResourceGroupName; - this.FooName = resourceIdentifer.ParentResource; - this.Name = resourceIdentifier.ResourceName; - } - - ChildFoo childFoo = null; - try - { - childFoo = this.MySDKClient.ChildFoo.Get(this.ResourceGroupName, this.FooName, this.Name); - } - catch - { - childFoo = null; - } - - if (childFoo == null) - { - throw new Exception(string.Format("A ChildFoo with name '{0}' in resource group '{1}' under parent Foo '{2}' does not exist. Please use New-AzChildFoo to create a ChildFoo with these properties.", this.Name, this.ResourceGroupName, this.FooName)); - } - - childFoo.Property1 = this.IsParameterBound(c => c.Property1) ? this.Property1 : childFoo.Property1; - childFoo.Property2 = this.IsParameterBound(c => c.Property2) ? this.Property2 : childFoo.Property2; - ... - - if (this.ShouldProcess(this.Name, string.Format("Updating Foo '{0}' in resource group '{1}' under parent Foo '{2}'.", this.Name, this.ResourceGroupName, this.FooName))) - { - var result = new PSChildFoo(this.MySDKClient.ChildFoo.Update(this.ResourceGroupName, this.FooName, this.Name, childFoo) - WriteObject(result); - } - } - } -} -``` - -
-