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

Connect-DbaInstance - Make AccessToken more convenient #7868

Merged
merged 1 commit into from
Oct 18, 2021

Conversation

potatoqualitee
Copy link
Member

Now, Connect-DbaInstance will automatically figure out the AccessToken, even if another type of object is returned.

Copy link
Contributor

@andreasjordan andreasjordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a great idea - thanks very much. Have no time to test the code, but changes look very good. I don't see a problem, so go ahead and merge.

@@ -876,6 +877,16 @@ function Connect-DbaInstance {

# If we have an AccessToken, we will build a SqlConnection
if ($AccessToken) {
# Check if token was created by New-DbaAzAccessToken or Get-AzAccessToken
Write-Message -Level Debug -Message "AccessToken detected, checking for string or PsObjectIRenewableToken"
if ($AccessToken | Get-Member | Where-Object Name -eq GetAccessToken) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can utilize checking the exact type using -is [TypeName] in PowerShell; may run a bit more efficient. (It is one that has been in .NET for long time show should work back to PS 3.0 as well.)

if ($AccessToken -is [PSObjectIRenewableToken]) {

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's quite a bit faster! I'll update, thank you 🙇🏼

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, that class is not available until the command is run. So if I do a test, and it's any other type of object, there will be an error

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, in the context of the function they have to pass the object so it will exists.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More formal method would be to set the type of the parameter you are expecting. If you want them to pass in the object from the output of the other commands, just set the parameter as the type. (cuts out having to check for it)

@potatoqualitee potatoqualitee merged commit a51b142 into development Oct 18, 2021
@potatoqualitee potatoqualitee deleted the accesstoken branch October 18, 2021 08:06
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

3 participants