-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUninstallAgentZabbixwithChocoV3.ps1
59 lines (52 loc) · 2.66 KB
/
UninstallAgentZabbixwithChocoV3.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
$PClisting = [System.Collections.ArrayList]@()
if ($PClisting -ne $null)
{
foreach ($RemoteComputer in $PClisting)
{
If (Test-Connection -ComputerName $RemoteComputer -Quiet)
{
try
{
Invoke-Command -ComputerName $RemoteComputer -ScriptBlock {
Set-ExecutionPolicy Unrestricted
# Check if choco is installed
$choco_install_ON = Test-Path "C:\ProgramData\chocolatey" #Verification d'installation de choco
$zabbix_install_ON = Test-Path "C:\Program Files\Zabbix Agent" #Verification d'installation de Zabbix
$smartmontools_install_ON = Test-Path "C:\Program Files\smartmontools" #Verification d'installation de
si choco n'est installé -> installation + si choco installé -> upgrade
if (-not $choco_install_ON) {
Write-Host "Installing choco on $RemoteComputer" -ForegroundColor Yellow
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
} else {
Write-Host "Upgrading choco on $RemoteComputer" -ForegroundColor Yellow
choco upgrade chocolatey
}
#si smart est installé -> désinstallation
if ($smartmontools_install_ON) {
Write-Host "Uninstalling smartmontools on" $RemoteComputer -ForegroundColor Yellow
choco uninstall smartmontools -y --removedependencies
} else {
Write-Host "No smartmontools on" $RemoteComputer -ForegroundColor Cyan
}
#si zabbix est installé -> désinstallation
if ($zabbix_install_ON) {
Write-Host "Uninstalling Zabbix Agent on" $RemoteComputer -ForegroundColor Yellow
choco uninstall zabbix-agent2 -y --removedependencies
} else {
Write-Host "No zabbix agent on" $RemoteComputer -ForegroundColor Cyan
}
}
}
catch
{
Write-Host "Something was getting wrong: " $RemoteComputer-ForegroundColor Red
}
Write-Host "Task successfully completed on: " $RemoteComputer -ForegroundColor Green
}
else
{
Write-Host "Can't connect to PC: " $RemoteComputer -ForegroundColor Red
}
}
}