Guest User

Untitled

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