Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >SQLCMD -S "(localdb)mssqllocaldb"
- SELECT @@SERVERNAME;
- SELECT @@SERVICENAME;
- SQLCMD -S 127.0.1.12mssqllocaldb
- SQLCMD -S Hostname,PORT
- $SQLServer = '.' ##Set Server Name
- $SQLService = Get-WmiObject -ComputerName $SQLServer win32_service | where {$_.name -like "MSSQL*"} #Find instance info from services.
- $SQLInstance = $($SQLService.name) #Set name
- $SQLInstanceName = $SQLInstance.substring(6) ##Remove MSSQL$ from service name. This is a ghetto method and the best I could do in 5 mins.
- write-output "Powershell output- SQL Instance Name is: $($SQLInstanceName)"
- ##Query information##
- $Query = "set nocount on; select 'SQL SVC: ' + @@servicename; select 'SQL Server: ' + @@SERVERNAME"
- Write-Verbose "SQL Query to be executed: '$($Query)'"
- osql -E -S "$Server$SQLInstanceName" -Q $Query -m 10 -h-1 ##Your command.
Add Comment
Please, Sign In to add comment