#Requires -RunAsAdministrator Function Disable-Sleep { If (!(Test-Path "C:\ProgramData\chocolatey\lib\dontsleep.portable\tools\DontSleep_x64_p.exe")) { If (!(Get-Command choco -ErrorAction SilentlyContinue)) {Install-Choco} choco install dontsleep.portable -y } & C:\ProgramData\chocolatey\lib\dontsleep.portable\tools\DontSleep_x64_p.exe -bg please_sleep_mode=0 enable=1 } Function Enable-Sleep { If (Get-Process -Name "DontSleep_x64_p") { Write-Host "Resuming power management plan" Stop-Process -Name "DontSleep_x64_p" -Force } Else { Write-Host "Disable-Sleep wasn't running. Did you run 'Disable-Sleep'?" } } function InstallAgent { Write-Host Write-Host ================ Agent Installation ================ Write-Host Downloading the agent for $SelectedSite.Site $msiURL = $SelectedSite.msiURL $msiURL = "https://prod.setup.itsupport247.net/windows/MSMA/32/atg_ACG_MSMA_ITSPlatform_TKN3882d625-3bbf-4ad5-9ca0-d226ec86ad7d/MSI/setup" $pos = $msiURL.IndexOf("/atg_") $rightPart = $msiURL.Substring($pos + 1) $pos = $rightPart.IndexOf("/setup") $leftPart = $rightPart.Substring(0, $pos) $msiFileName = $leftPart -replace "/MSI", ".msi" $msiFolder = $ENV:SystemDrive + '\Ambitions\ITS247Agent\' $msiFilePath = $msiFolder + $msiFileName (New-Object System.Net.WebClient).DownloadFile($msiURL, $msiFilePath) $null = (New-Item -ItemType Directory -Force -Path 'C:\Ambitions\ITS247Agent') Get-ChildItem 'C:\Ambitions\ITS247Agent' | Unblock-File Write-Host Disabling Windows Defender Real Time Scanning Set-MpPreference -DisableRealtimeMonitoring $true Disable-Sleep If ($Silent) { Write-Host Installing the agent for $SelectedSite.Site silently. No errors will be shown. Start-Process "msiexec.exe" -ArgumentList "/I $msiFilePath /q" -Wait -NoNewWindow } else { Write-Host Installing the agent for $SelectedSite.Site interactively Start-Process "msiexec.exe" -ArgumentList "/I $msiFilePath" -Wait -NoNewWindow } Write-Host "`nRemember: If powershell seems frozen you might have clicked in the window. Try clicking in the window again and press the ESC key to unfreeze.`n" Do { $IRStart = Get-Date $IRStartHM = Get-Date -Format hh:mm $Process = "irsetup" If (!(Get-Process $Process -ErrorAction SilentlyContinue)) { Write-Host -NoNewLine "`rWaiting for $Process to Start" Start-Sleep -Seconds 2 } Else { Write-Host "`n" Write-Host "$Process has Started" $IRStart = Get-Date While (Get-Process $Process -ErrorAction SilentlyContinue) { [int32]$IRWait = (New-TimeSpan -Start $IRStart -End $(Get-Date)).TotalMinutes Write-Host -NoNewLine "`rWaiting for $Process to stop since $IRStartHM, it's been $IRWait minutes" Start-Sleep -Seconds 2 } Write-Host "$Process Stopped" ; $Status = 'Done' } }Until ($Status) 1..3 | ForEach-Object { [console]::Beep(1200, 505); Start-Sleep .505 }; [console]::Beep(1800, 1500) Disable-Sleep Exit } #End of InstallAgent InstallAgent