Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Connect-AzureADExporter.ps1 with dynamic tab autocomplete for environment name #23

Merged
merged 1 commit into from
Aug 23, 2022

Conversation

SamErde
Copy link
Contributor

@SamErde SamErde commented Jun 28, 2022

Used ArgumentCompleter (backwards compatible with Windows PowerShell 5.1) to dynamically pull Azure environment names for tab autocomplete of the Environment parameter.

Resolves issue #22 (tab autocomplete for Azure environment names should not be hard coded).

Used ArgumentCompleter (backwards compatible with Windows PowerShell 5.1) to dynamically pull Azure environment names for tab autocomplete of the Environment parameter.
@SamErde
Copy link
Contributor Author

SamErde commented Jun 28, 2022

That commit gives us dynamic tab autocomplete, but I just realized that it doesn't validate inputs. Would this be better?

function Connect-AzureTestCompatible {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$false)]
        [ArgumentCompleter( {
            param ( $CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters )
            $Global:EnvironmentNames = (Get-MgEnvironment).Name; $EnvironmentNames
        } )]
        [ValidateScript({
            if ($_ -in $Global:EnvironmentNames) {
                $true
            } else {
                throw "$_ is not a valid environment name. Please use one of the following: $($Global:EnvironmentNames -join ', ')"
            }
        })]
        [string]$Environment
    )
    write-output $Environment
}

@merill merill merged commit f685f05 into microsoft:main Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants