dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.44k stars 796 forks source link

Copy-DbaLogin / Get-DbaLogin - does not seem to work properly when using array called $sqllogins as input #9290

Closed DiHo78 closed 6 months ago

DiHo78 commented 6 months ago

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

No error but also no proper outcome of Copy-DbaLogin See code example below Customer of ours tried to utilize Copy-DbaLogin in combination with an array of given logins to copy. Called it $sqllogins which seems to collide with a check inside Get-DbaLogin
Thx to @jpomfret for already having a 1st look

Steps to Reproduce

Import-Module dbatools -Verbose
Set-DbatoolsInsecureConnection -SessionOnly

$source = 'MySourceInstance'
$destination = 'MyTargetInstance'

#Shows all avaibale Logins/groups
Get-DbaLogin -SqlInstance $source |ft 

$sqllogins = @(
"myDomain\UserA",
"myDomain\UserB")

#does not do anything
Copy-DbaLogin -Login $sqllogins -Source $source -Destination $destination -Force -verbose #-WhatIf

#Now only shows SQLLogins
get-dbalogin -SqlInstance $source | ft

#empty array
$sqllogins = @()

#works again as expected
get-dbalogin -SqlInstance $source | ft

Please confirm that you are running the most recent version of dbatools

dbatools version 2.1.10

Other details or mentions

No response

What PowerShell host was used when producing this error

Windows PowerShell ISE (powershell_ise.exe)

PowerShell Host Version

Name Value


PSVersion 5.1.17763.5576
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.5576
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

SQL Server Edition and Build number

Microsoft SQL Server 2019 (RTM-CU25) (KB5033688) - 15.0.4355.3 (X64) Jan 30 2024 17:02:22 Copyright (C) 2019 Microsoft Corporation Standard Edition (64-bit) on Windows Server 2019 Standard 10.0 (Build 17763: ) (Hypervisor)

.NET Framework Version

.NET Framework 4.8.4645.0

jpomfret commented 6 months ago

The issue relates to this - when $sqllogins is the name of the parameter it trips this if statement - which then sets the $Type = 'sql'

image

Looking back through the git history for this file - there used to be parameters for SQLLogins and WindowsLogins - this was later simplified to use the Type parameter.

image

Now that Type is a parameter and SqlLogins, WindowsLogins no longer exist we can tidy up the code to resolve this issue... PR incoming!