-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-WhoIsActive.ps1
35 lines (27 loc) · 1.07 KB
/
Get-WhoIsActive.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Import-Module SqlPs -DisableNameChecking
Function Get-WhoIsActive {
[CmdletBinding()]
Param(
[string]$Uri
)
[System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression') | Out-Null
$DownloadUri = $Uri + (Invoke-WebRequest -Uri $Uri).Links[0].href
$ZipBytes = Invoke-WebRequest -Uri $DownloadUri
$ZipStream = New-Object System.IO.Memorystream
$ZipStream.Write($ZipBytes.Content,0,$ZipBytes.Content.Length)
$ZipArchive = New-Object System.IO.Compression.ZipArchive($ZipStream)
$ZippedFile = $ZipArchive.GetEntry($ZipArchive.Entries[0])
$EntryReader = New-Object System.IO.StreamReader($ZippedFile.Open())
$Document = $EntryReader.ReadToEnd()
return $Document
}
Function Add-SpWhoIsActive {
[CmdletBinding()]
Param(
[string]$ServerInstance
)
$spWhoIsActive = Get-WhoIsActive -Uri "http://www.whoisactive.com/"
Write-Verbose "Deploying sp_whoisactive"
Invoke-Sqlcmd -ServerInstance localhost -Database master -Query $spWhoIsActive
}
Add-SpWhoIsActive -ServerInstance localhost -Verbose