Guest User

Untitled

a guest
Apr 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. using (PowerShell PowerShellInstance = PowerShell.Create())
  2. {
  3. string query = string.Format(@"$server = ""{0}""
  4. $db = ""master""
  5. $sql = ""SELECT DISTINCT hostprocess FROM master.dbo.sysprocesses WHERE last_batch < DATEADD(MINUTE, -30, GETDATE()) ""
  6. $user = ""{1}""
  7. $pass = ""{2}""
  8. $processId = Invoke-sqlcmd -Server $server -Database $db -Username $user -Password $pass -Query $sql | select -ExpandProperty hostprocess
  9. Write-Output $processId", Server, DbUserName, DbPass);
  10. PowerShellInstance.AddScript(query);
  11. var results = PowerShellInstance.Invoke();
  12. }
Add Comment
Please, Sign In to add comment