I am trying to user PowerShell to connect to a SQL server as follows:Server A - PowerShell script runs here. - Uses Microsoft.SqlServer.Smo namespace to make the connection to Server B - Using ConnectAsUsername with a active directory FID.Server B - SQL server - Active directory FID permissioned correctly to database.My problem is that on Server A, the FID needs to have the "Allow Log on locally" User Right Assignment for the connection attempt to Server B to work. I find this strange since I am not actually connecting to Server A with the FID. The error message received is the usual ""Logon failure: the user has not been granted the requested logon type at this computer.". My testing has shown that the FID does not need any URA assignments on Server B.Is there a way to avoid granting the "Allow Log on locally" User Right Assignment? Perhaps a different approach?This is the code running on Server A:[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo")[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")$sqlServer = "xxxxxxxx,1433"$serverConnection = new-object Microsoft.SqlServer.Management.Common.ServerConnection($sqlServer)$SQLQuesryResults = ""$SQLData = ""$serverConnection.ConnectAsUser = $true#$serverConnection.ConnectAsUsername = "user123@adomain.net"$serverConnection.ConnectAsUserPassword = "MyPassword"$serverConnection.Connect()
↧