merddyin / ADDeploy

Used to deploy components to support an ESAE forest and RBAC model via native control.
MIT License
2 stars 0 forks source link

Improve parameter sets in Set-ADDOUStructure #11

Closed PatrickOnGit closed 1 year ago

PatrickOnGit commented 1 year ago

To simplify command line input for an operator, the parameter validation in Set-ADDOUStructure should be improved:

    [CmdletBinding(DefaultParameterSetName="ChainRun")]
    Param(

        [Parameter(Mandatory = $true,Position=0)]
        [System.Management.Automation.PSCredential]
        $DACredential, 

        [Parameter(ParameterSetName="Add_Focus",Mandatory=$true,Position=1)]
        [Parameter(ParameterSetName="Remove_Focus",Mandatory=$true,Position=1)]
        [Parameter(ParameterSetName="ChainRun",Mandatory=$true,Position=1)]
        [Parameter(ParameterSetName="Remove_SL", Mandatory=$true,Position=1)]
        [Parameter(ParameterSetName="Add_SL", Mandatory=$true,Position=1)]
        [Parameter(ParameterSetName="Remove_SLO", Mandatory=$true,Position=1)]
        [Parameter(ParameterSetName="Add_SLO", Mandatory=$true,Position=1)]
        [Parameter(ParameterSetName="Add_Class", Mandatory=$true,Position=1)]
        [Parameter(ParameterSetName="Remove_Class", Mandatory=$true,Position=1)]
        [ValidateSet("SL","SLO","Class","ALL")]
        [string]$OULevel,

        [Parameter(ParameterSetName="Add_Focus",Mandatory=$true,Position=2)]
        [Parameter(ParameterSetName="Remove_Focus",Mandatory=$true,Position=2)]
        [Parameter(ParameterSetName="Remove_SL", Mandatory=$true,Position=2)]
        [Parameter(ParameterSetName="Add_SL", Mandatory=$true,Position=2)]
        [Parameter(ParameterSetName="Remove_SLO", Mandatory=$true,Position=2)]
        [Parameter(ParameterSetName="Add_SLO", Mandatory=$true,Position=2)]
        [Parameter(ParameterSetName="Add_Class", Mandatory=$true,Position=2)]
        [Parameter(ParameterSetName="Remove_Class", Mandatory=$true,Position=2)]
        [ValidateSet("Tier-0","Tier-1","Tier-2")]
        [string]$TierName,

        [Parameter(ParameterSetName="Add_Focus",Mandatory=$true,Position=3)]
        [Parameter(ParameterSetName="Remove_Focus",Mandatory=$true,Position=3)]
        [Parameter(ParameterSetName="Remove_SL", Mandatory=$true,Position=3)]
        [Parameter(ParameterSetName="Add_SL", Mandatory=$true,Position=3)]
        [Parameter(ParameterSetName="Remove_SLO", Mandatory=$true,Position=3)]
        [Parameter(ParameterSetName="Add_SLO", Mandatory=$true,Position=3)]
        [Parameter(ParameterSetName="Add_Class", Mandatory=$true,Position=3)]
        [Parameter(ParameterSetName="Remove_Class", Mandatory=$true,Position=3)]
        [ValidateSet("ADM","SRV","STD")]
        [string]$FocusName,

        [Parameter(ParameterSetName="Remove_SL", Mandatory=$true,Position=4)]
        [Parameter(ParameterSetName="Add_SL", Mandatory=$true,Position=4)]
        [Parameter(ParameterSetName="Remove_SLO", Mandatory=$true,Position=4)]
        [Parameter(ParameterSetName="Add_SLO", Mandatory=$true,Position=4)]
        [Parameter(ParameterSetName="Add_Class", Mandatory=$true,Position=4)]
        [Parameter(ParameterSetName="Remove_Class", Mandatory=$true,Position=4)]
        [string]$SLName,

        [Parameter(ParameterSetName="Remove_SLO", Mandatory=$true,Position=5)]
        [Parameter(ParameterSetName="Add_SLO", Mandatory=$true,Position=5)]
        [Parameter(ParameterSetName="Add_Class", Mandatory=$true,Position=5)]
        [Parameter(ParameterSetName="Remove_Class", Mandatory=$true,Position=5)]
        [string[]]$SLOName, 

        [Parameter(ParameterSetName="Add_Class", Mandatory=$true,Position=6)]
        [Parameter(ParameterSetName="Remove_Class", Mandatory=$true,Position=6)]
        [ValidateSet("Users","Workstations","Groups")]
        [string[]]$ClassName,

        [Parameter(ParameterSetName="Remove_Focus",Mandatory=$true)]
        [Parameter(ParameterSetName="Remove_SL", Mandatory=$true)]
        [Parameter(ParameterSetName="Remove_SLO", Mandatory=$true)]
        [Parameter(ParameterSetName="Remove_Class", Mandatory=$true)]
        [switch]$Remove,

        [Parameter(ParameterSetName="ChainRun")]
        [switch]$ChainRun
    )
merddyin commented 1 year ago

The updated code base actually contains a full re-write of this function. It was required as a number of elements, such as the ValidateSet block for FocusName, are statically configured. This led to an issue as I had a scenario where the customer wanted to be able to rename these to different values. The updated code now pulls these values from a table in the DB and populates an argument completer, as well as shifting to ValidateScript. During the process, it became evident that the entire function could be substantially more efficient, along with several other functions. I've honestly been meaning to complete the updates and get them committed, but been super busy with work. Needing to get these updates in is why I haven't ever published to the PSGallery.

merddyin commented 1 year ago

Closing this as there is no longer a Set-ADDOUStructure in v1.4.6, which is currently in the dev branch.