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

Export-DbaLogin - Allow Login and ExcludeLogin to work with SMO objects #5194

Merged
merged 4 commits into from
Mar 16, 2019
Merged

Conversation

awickham10
Copy link
Contributor

Type of Change

  • Bug fix (non-breaking change, fixes Exporting login produces empty file #4604 )
  • New feature (non-breaking change, adds functionality)
  • Breaking change (effects multiple commands or functionality)
  • Ran manual Pester test and has passed (`.\tests\manual.pester.ps1)
  • Adding code coverage to existing functionality
  • Pester test is included
  • If new file reference added for test, has is been added to github.com/sqlcollaborative/appveyor-lab ?
  • Nunit test is included
  • Documentation
  • Build system

Purpose

Fix issue where Login objects being passed in to Login or ExcludeLogin parameters don't get processed correctly due SMO Login's ToString method putting login names in square brackets.

Approach

If Login is an array, check first item to see if it's a Login object. If it is, make Login the $Login.Name property value instead of $Login - this property does not include square brackets unlike when $Login is used and ToString() gets called. If it's not an array, we just use $Login.Name.

The same applies to ExcludeLogin.

Commands to test

Get-DbaLogin -SqlInstance 'MyServer' | Where-Object { $_.IsDisabled -eq $false } | % { Export-DbaLogin -SqlInstance 'MyServer' -Login $_ }

@potatoqualitee
Copy link
Member

thanks for this! any interest in adding $InputObject so you dont have to | % ?

it'll sorta undo this PR a lil bit but I think it'd be a fab addition. im surprised it doesnt currently support InputObject

@awickham10
Copy link
Contributor Author

Sure - I'll take a stab at it.

@awickham10
Copy link
Contributor Author

I feel like this got ugly fast...

@potatoqualitee
Copy link
Member

i tend to avoid parametersets - they can pass sqlinstance or inputobject, then if ($sqlinstance) build inputobject then go from there 👍 cant find a good example tho :/

@potatoqualitee
Copy link
Member

fantastic, thank you, @awickham10 !

@potatoqualitee potatoqualitee merged commit 2fce5f7 into dataplat:development Mar 16, 2019
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.

Exporting login produces empty file
2 participants