dataplat / dbatools

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

Test-DbaMaxMemory to other domain computer fails due to trying to use original domain #3882

Closed therealcode closed 5 years ago

therealcode commented 6 years ago

Version: 0.9.384

Issue

When on DOMAIN1 and trying to use Test-DbaMaxMemory on a server on DOMAIN2 - the domain credentials supplied are ignored and it uses the domain credentials the PS session is on.

However, this works fine when using Test-DbaPowerPlan.

Reproducible Example

Example from PS Session on DOMAIN1: PS: Test-DbaMaxMemory -SqlServer APP01 -Credential DOMAIN2\ADMIN_USER or PS: Test-DbaMaxMemory -SqlServer APP01 -Credential ADMIN_USER@DOMAIN2.local

Expected Behavior

ComputerName : APP01 InstanceName : MSSQLSERVER SqlInstance : APP01 InstanceCount : 1 TotalMB : 118772 SqlMaxMB : 2147483647 RecommendedMB : 101364

Actual Behavior

Error Returned - Regardless of which line in example was used: "Exception calling "Open" with "0" argument(s): "Login failed for user 'DOMAIN1\ADMIN_USER'."" WARNING: [15:25:37][Test-DbaMaxMemory] Failure | Login failed for user 'DOMAIN1\ADMIN_USER'.

It shouldn't be sending DOMAIN1\ADMIN_USER when parameter specified is DOMAIN2\ADMIN_USER.

Environmental data

Stuart-Moore commented 6 years ago

You appear to be just providing usernames, you need to pass a PsCredential object:

$cred = Get-Credential 
Test-DbaMaxMemory -SqlServer APP01 -Credential $cred
therealcode commented 6 years ago

The above also doesn't work. It still returns the alternate domain as an error.

Attempt With Suggested

$cred = Get-Credential (DOMAIN2\ADMIN_USER + PW on prompt) Test-DbaMaxMemory -SqlServer APP01 -Credential $cred

Result

WARNING: [13:41:54][Test-DbaMaxMemory] Failure | Login failed for user 'DOMAIN1\ADMIN_USER'.

More Info

After passing my original input - a pop-up opens to enter my password. I'm aware there's a workaround by saving the cred to a variable, but figured it would be nice if this method worked the same as Test-DbaPowerPlan (where entering the pass in the pop-up afterwards works fine).

niphlod commented 5 years ago

prolly related to https://github.com/sqlcollaborative/dbatools/issues/1980 . for now, let's condider this still open.

potatoqualitee commented 5 years ago

this will work now 💯