Created
February 11, 2016 16:24
-
-
Save vsliouniaev/9086cbc8366c356c0a50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(${env:InstalledStatusMonitor} -eq 1) | |
{ | |
Write-Host "Status monitor has already been installed on this machine by this script" -ForegroundColor Green | |
} | |
Write-Host "Using chocolatey to install the Web Platform Installer ..." -ForegroundColor Green | |
iex ((new-object net.webclient).downloadstring('https://chocolatey.org/install.ps1')) | |
cinst webpi -y | |
Stop-Process -Name WebPlatformInstaller | |
Write-Host "Using Web Platform Installer to install Status Monitor ..." -ForegroundColor Green | |
&"$env:ProgramFiles\Microsoft\Web Platform Installer\WebpiCmd.exe" /Install /AcceptEula /Products:ApplicationInsightsStatusMonitor | |
Write-Host "Adding app pool account to the 'Performance Monitor Users' local group" -ForegroundColor Green | |
$group = "Performance Monitor Users" | |
$user = "Network Service" | |
$computer = $(Get-WmiObject Win32_Computersystem).name | |
$de = [ADSI]"WinNT://$computer/$group,group" | |
$de.psbase.Invoke("Add",([ADSI]"WinNT://$user").path) | |
Write-Host "Waiting 30 seconds for Status Monitor to finish its install ..." -ForegroundColor Green | |
Start-Sleep -Seconds 30 | |
Write-Host "Stop-Starting services to enable tracing..." -ForegroundColor Green | |
# For some reason, even though Status Monitor calls "iisreset.exe /restart" | |
# calling it here leaves IIS and website stopped. | |
&iisreset.exe /restart | |
Write-Host "waiting a few seconds..." -ForegroundColor Yellow | |
Start-Sleep -Seconds 2 | |
Write-Host "starting..." -ForegroundColor Yellow | |
Start-Service -Name W3SVC | |
Get-WebApplication | Select ApplicationPool -Unique | %{ Start-WebAppPool $_.applicationPool } | |
Get-Website | Start-Website | |
Write-Host "started" -ForegroundColor Yellow | |
Write-Host "Cleaning up running applications" -ForegroundColor Green | |
Stop-Process -Name Microsoft.Diagnostics.Agent.StatusMonitor | |
Write-Host "Setting environment variable to indicate status monitor has been installed" -ForegroundColor Green | |
[Environment]::SetEnvironmentVariable("InstalledStatusMonitor", "1", "Machine") | |
Write-Host "Installation complete" -ForegroundColor Green |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment