-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerCLISetSNMP.ps1
More file actions
87 lines (34 loc) · 1.77 KB
/
PowerCLISetSNMP.ps1
File metadata and controls
87 lines (34 loc) · 1.77 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# The following blog post describes this script: https://pascalswereld.nl/2014/05/03/powercli-collection-adding-snmp-settings-to-esxi/
#Settings
$vCenterFQDN = Read-Host “Enter vCenter FQDN: “
$ClusterName = Read-Host “Enter Cluster name of hosts that will need to be changed: “
$trapDestination = Read-Host “SNMP Trap Mgmt server hostname: “
$trapCommunity = Read-Host “Trap Community Name: “
$ReadOnlyCommunity = Read-Host “Read Only Community Name: “
# Running no need to change under this line
# Connect to the vCenter server
Write-Host “vCenter credentials”
$viServer = Connect-VIServer -Server $vCenterFQDN -Credential (Get-Credential)
# Get all hosts in vCenter managed Cluster so we can cycle thru them
$Hosts = Get-Cluster -Name $ClusterName | Get-VMHost
# Get ESXi Host credentials
Write-Host “ESXi host credentials”
$EsxCred = Get-Credential
# Cycle through each host
ForEach ($VMHost in $Hosts)
{
# Need to connect to ESXi itself
$esxconnect = Connect-VIServer -Server $VMHost -Credential $EsxCred
# Get snmp object
$snmpConn = Get-VMHostSnmp
# Enable snmp
Set-VMHostSnmp -HostSnmp $snmpConn -Enabled:$true
# Set read-only community
Set-VMHostSnmp -HostSnmp $snmpConn -ReadOnlyCommunity $ReadOnlyCommunity
# Set trap target host and trap community
Set-VMHostSnmp -HostSnmp $snmpConn -AddTarget -TargetCommunity $trapCommunity -TargetHost $trapDestination
# Disconnect-VIServer
Disconnect-VIServer -Server $esxconnect -Confirm:$false
}
#disconnect from ESX server
Disconnect-VIServer -Server $viServer -Confirm:$false