January 19, 2017 at 11:34 am
Hello
I executed the below command to extract the login to a .sql file.
sqlcmd -E -S server -d master -Q "set nocount on; exec master..sp_help_revlogin; set nocount off;" -o "c:\Logins.sql"
But while importing and executing the same .sql file to another sql instance - getting below error -
PS SQLSERVER:\> invoke-sqlcmd -inputfile "c:\Logins.sql" -serverinstance server -database "master" | Out-File -filePath "c:\file_logins.txt"
invoke-sqlcmd : Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
The identifier that starts with 'ma
' is too long. Maximum length is 128.
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous
statement must be terminated with a semicolon.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
The identifier that starts with 'mast
' is too long. Maximum length is 128.
Incorrect syntax near the keyword 'FROM'.
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous
statement must be terminated with a semicolon.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near ','.
At line:1 char:1
+ invoke-sqlcmd -inputfile "c:\Logins.sql" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Invoke-Sqlcmd], SqlPowerShellSqlExecutionException
+ FullyQualifiedErrorId : SqlError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
Thanks.
January 19, 2017 at 11:49 am
SQL-DBA-01 - Thursday, January 19, 2017 11:34 AMHelloI executed the below command to extract the login to a .sql file.
sqlcmd -E -S server -d master -Q "set nocount on; exec master..sp_help_revlogin; set nocount off;" -o "c:\Logins.sql"But while importing and executing the same .sql file to another sql instance - getting below error -
PS SQLSERVER:\> invoke-sqlcmd -inputfile "c:\Logins.sql" -serverinstance server -database "master" | Out-File -filePath "c:\file_logins.txt"
invoke-sqlcmd : Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
The identifier that starts with 'ma
' is too long. Maximum length is 128.
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous
statement must be terminated with a semicolon.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
The identifier that starts with 'mast
' is too long. Maximum length is 128.
Incorrect syntax near the keyword 'FROM'.
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous
statement must be terminated with a semicolon.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near ','.
At line:1 char:1
+ invoke-sqlcmd -inputfile "c:\Logins.sql" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Invoke-Sqlcmd], SqlPowerShellSqlExecutionException
+ FullyQualifiedErrorId : SqlError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
Have you reviewed the c:\Logins.sql file to search for any possible errors on it?
January 19, 2017 at 12:06 pm
If I copy and paste the entire sql to ssms and run it, it just runs without having any error
Thanks.
January 19, 2017 at 12:18 pm
Hi Luis
I thought to copy the .sql o/p and running it manually. When I do that I found that the extract through sqlcmd did not work properly. Many places, it just extracted few portion.
sqlcmd -E -S server-d master -Q "set nocount on; exec master..sp_help_revlogin; set nocount off;" -o "c:\Logins.sql"
Do I have to modify the script so that It will extract the entire output while the proc sp_help_revlogin is being called via sqlcmd.?
Please suggest.
Thanks.
January 19, 2017 at 12:31 pm
Can I use something like this? But this is giving me error -
Message
Executed as user: . Msg 105, Level 15, State 1, Server , Line 1 Unclosed quotation mark after the character string 'declare @t table(names varchar(8000)) '. Process Exit Code 0. The step succeeded. File is not being generated though.
sqlcmd -E -S servername -d master -Q "declare @t table(names varchar(8000))
insert into @t
exec master..sp_help_revlogin
set nocount on
select * from @t
set nocount off;" -o "D:\Logins\Logins.sql"
Thanks.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply