Prerequisites:
1. Retrieve your device key form the Site 24 by 7 Portal
2. From the same portal install Site24x7WindowsAgent.msi on whatever host you have access to. Put in in C:\Temp
3. WinRM needs to work between hosts.
Here is the script:
$today = Get-Date -UFormat '%Y-%m-%d_%H%M'
Start-Transcript -Path "C:\Temp\Site24x7InstallLog-"+$today+".txt"#Here is where you specify your target machines
$targetHosts = @(
#'FQDN'#'FQDN'
#'FQDN')function InstallSite24 {
$installerPath = 'C:\Temp\Site24x7WindowsAgent.msi'
#PUT DEVICE KEY FROM SITE 24 BY 7 BELOW after the =
$deviceKey = ENTERDEVICEKEY
if (Test-Path $installerPath) {
Write-Host "The Site24x7 Windows agent installer was found at $installerPath."
Write-Host "The following hosts will have the Site24x7 Windows agent installed and automation mode enabled:`n$($targetHosts -join "`n")" -ForegroundColor Yellow
$confirm = Read-Host "Confirm? (y/n)" if ($confirm -eq 'y') {
foreach ($targetHost in $targetHosts) {
Write-Host "Uninstalling existing Site24x7 Windows agent from $targetHost ..."
Invoke-Command -ComputerName $targetHost {
$site24Agent = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -eq "Site24x7 Windows Agent"}
Write-Host $site24Agent -ForegroundColor Cyan
$site24Agent.Uninstall()
} Write-Host "Copying Site24x7 Windows agent installer to $targetHost ..."
$session = New-PSSession -ComputerName $targetHost
Copy-Item -Path $installerPath -ToSession $session -Destination 'C:\Temp'
#Copy-Item -Path $installerPath -Destination "\\$targetHost\C$\Temp" Write-Host "Installing Site24x7 Windows agent on $targetHost ..."
Invoke-Command -ComputerName $targetHost -ScriptBlock {
param(
[string]$deviceKey
)
$path = 'C:\Temp\Site24x7WindowsAgent.msi'$args = "/i `"$path`" EDITA1=$deviceKey automation=true /qn"
$lastExitCode = (Start-Process -FilePath 'msiexec.exe' -ArgumentList $args -Wait -PassThru).ExitCodeif ($lastExitCode -eq 0) {
Write-Host "Site24x7 Windows agent installed successfully on $($env:COMPUTERNAME)." -ForegroundColor Green
}
else {
Write-Host "Site24x7 Windows agent installation failed on $($env:COMPUTERNAME). Exit code: $($lastExitCode)" -ForegroundColor Red
}
} -ArgumentList ($deviceKey)
}
}
elseif ($confirm -eq 'n') {
Write-Host "Aborting installation."
}
else {
Write-Host "Invalid response. Please enter 'y' or 'n'."
}
}
else {
Write-Host "The Site24x7 Windows agent installer was not found at $installerPath. Aborting installation."
}
} Write-Host "Please confirm the host list is correct:`n$($targetHosts -join "`n")" -ForegroundColor Cyan
$confirm = Read-Host "Confirm? (y/n)"if ($confirm -eq 'y') {
InstallSite24
}
else {
Write-Host "Aborting installation."
}Stop-Transcript