Simple Network Management Protocol (SNMP) is a popular protocol for network management. It is used for collecting information from, and configuring, network devices, such as servers, printers, hubs, switches, and routers on an Internet Protocol (IP) network. Here in this article, I am configuring snmp on VMWare ESXi to send trap. Below are the esxcli commands which configures, get and test SNMP configuration on ESXi.

This will require SSH need to be enabled VMWARE SECURITY BEST PRACTICES: POWERCLI ENABLE OR DISABLE ESXI SSH.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #enables SNMP on Esxi esxcli system snmp set --enable true #Sets SNMP community on Esxi esxcli system snmp set --communities public #Sets SNMP target on ESXi esxcli system snmp set --targets=192.168.34.12 @162 /public #Configure and set firewall on ESXi esxcli network firewall ruleset set --ruleset-id snmp --allowed-all true esxcli network firewall ruleset set --ruleset-id snmp --enabled true #Restart SNMP daemon on Esxi /etc/init.d/snmpd restart #View current SNMP configuration on ESXi esxcli system snmp get #Test SNMP configuration by sending test snamp trap message. esxcli system snmp test

There are more and detailed configuration options available on Official VMWare Guide for SNMP

Few of my colleagues are junior, and little bit hesitant on using command line. As there are not much GUI options available to configure SNMP on ESXi, here I have created small basic GUI utility for esxi snmp configuration. Which tests, sets and gets the SNMP configuration from ESXi.

Download this script here, It is also available on github. To use these scripts make sure you follow below articles.

POWERCLI INITIALIZE-POWERCLI ENVIRONMENT.PS1 CANNOT BE LOADED BECAUSE RUNNING SCRIPTS IS DISABLED

VMWARE VSPHERE POWERCLI INSTALLATION AND CONFIGURATION STEP BY STEP

#$CurretSettings = $ErrorActionPreference #$ErrorActionPreference = 'SilentlyContinue' #Generated Form Function function GenerateForm { ######################################################################## # Generated On: 5/6/2018 12:39 AM # Generated By: vCloud-lab.com # Tested On: # Windows 10 # PowerCLI 6.5 # VMWare vSphere 6.5 ######################################################################## #region Import the Assemblies [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null #endregion #region Generated Form Objects $vCloudForm = New-Object System.Windows.Forms.Form $logoffvCenter = New-Object System.Windows.Forms.Button $Status1 = New-Object System.Windows.Forms.ProgressBar $status2 = New-Object System.Windows.Forms.StatusBar $TestSNMPtrap = New-Object System.Windows.Forms.GroupBox $Sendtrap = New-Object System.Windows.Forms.Button $SendTrapstatus = New-Object System.Windows.Forms.RichTextBox $CurrentConfL = New-Object System.Windows.Forms.GroupBox $url = New-Object System.Windows.Forms.LinkLabel $CurrentConfB = New-Object System.Windows.Forms.Button $CurrentConfBox = New-Object System.Windows.Forms.RichTextBox $SetSNMPGroup = New-Object System.Windows.Forms.GroupBox $ConfigureSNMP = New-Object System.Windows.Forms.Button $SNMPFirewall = New-Object System.Windows.Forms.CheckBox $SNMPService = New-Object System.Windows.Forms.CheckBox $SnmpConfBox = New-Object System.Windows.Forms.RichTextBox $ClusterEsxi = New-Object System.Windows.Forms.GroupBox $Esxil = New-Object System.Windows.Forms.Label $ClusterL = New-Object System.Windows.Forms.Label $EsxiList = New-Object System.Windows.Forms.ComboBox $ClusterList = New-Object System.Windows.Forms.ComboBox $AuthGroup = New-Object System.Windows.Forms.GroupBox $GetClusterInfo = New-Object System.Windows.Forms.Button $LoginvCenter = New-Object System.Windows.Forms.Button $vCenterName = New-Object System.Windows.Forms.TextBox $Publicbox = New-Object System.Windows.Forms.RichTextBox $TargetsLabel = New-Object System.Windows.Forms.Label $CommunitiesLabel = New-Object System.Windows.Forms.Label $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState #endregion Generated Form Objects $OnLoadForm_StateCorrection= {#Correct the initial state of the form to prevent the .Net maximized form issue $vCloudForm.WindowState = $InitialFormWindowState } #---------------------------------------------- #region Generated Form Code $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 445 $System_Drawing_Size.Width = 534 $vCloudForm.ClientSize = $System_Drawing_Size $vCloudForm.DataBindings.DefaultDataSourceUpdateMode = 0 $vCloudForm.Name = "vCloudForm" $vCloudForm.Text = 'GUI Esxi SNMP trap configuration tool by vcloud-lab.com' $vCloudForm.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen $AuthGroup.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 12 $System_Drawing_Point.Y = 12 $AuthGroup.Location = $System_Drawing_Point $AuthGroup.Name = "AuthGroup" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 79 $System_Drawing_Size.Width = 230 $AuthGroup.Size = $System_Drawing_Size $AuthGroup.TabIndex = 0 $AuthGroup.TabStop = $False $AuthGroup.Text = 'Authentication' $AuthGroup.add_Enter($handler_groupBox1_Enter) $vCloudForm.Controls.Add($AuthGroup) $vCenterName.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 6 $System_Drawing_Point.Y = 19 $vCenterName.Location = $System_Drawing_Point $vCenterName.Name = "vCenterName" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 20 $System_Drawing_Size.Width = 214 $vCenterName.Size = $System_Drawing_Size $vCenterName.TabIndex = 0 $vCenterNameWaterMark = 'Type vCenter computername or IP' $vCenterName.Text = $vCenterNameWaterMark $vCenterName.ForeColor = 'Darkgray' $vCenterName.add_TextChanged({$vCenterName.ForeColor = 'Black'}) $AuthGroup.Controls.Add($vCenterName) $LoginvCenter.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 6 $System_Drawing_Point.Y = 45 $LoginvCenter.Location = $System_Drawing_Point $LoginvCenter.Name = "LoginvCenter" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 102 $LoginvCenter.Size = $System_Drawing_Size $LoginvCenter.TabIndex = 1 $LoginvCenter.Text = "Login-vCenter" $LoginvCenter.UseVisualStyleBackColor = $True $LoginvCenter.add_Click($LoginvCenter_OnClick) $AuthGroup.Controls.Add($LoginvCenter) $logoffvCenter.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 12 $System_Drawing_Point.Y = 396 $logoffvCenter.Location = $System_Drawing_Point $logoffvCenter.Name = "logoffvCenter" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 126 $logoffvCenter.Size = $System_Drawing_Size $logoffvCenter.TabIndex = 3 $logoffvCenter.Text = "Logoff-vCenter" $logoffvCenter.UseVisualStyleBackColor = $True $logoffvCenter.add_Click($logoffvCenter_OnClick) $vCloudForm.Controls.Add($logoffvCenter) $Status1.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 303 $System_Drawing_Point.Y = 396 $Status1.Location = $System_Drawing_Point $Status1.Name = "Status1" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 21 $System_Drawing_Size.Width = 224 $Status1.Size = $System_Drawing_Size $Status1.TabIndex = 2 $vCloudForm.Controls.Add($Status1) $status2.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 0 $System_Drawing_Point.Y = 422 $status2.Location = $System_Drawing_Point $status2.Name = "status2" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 534 $status2.Size = $System_Drawing_Size $status2.TabIndex = 5 $vCloudForm.Controls.Add($status2) $TestSNMPtrap.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 249 $System_Drawing_Point.Y = 98 $TestSNMPtrap.Location = $System_Drawing_Point $TestSNMPtrap.Name = "TestSNMPtrap" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 114 $System_Drawing_Size.Width = 278 $TestSNMPtrap.Size = $System_Drawing_Size $TestSNMPtrap.TabIndex = 4 $TestSNMPtrap.TabStop = $False $TestSNMPtrap.Text = "Send test SNMP trap" $vCloudForm.Controls.Add($TestSNMPtrap) $Sendtrap.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 163 $System_Drawing_Point.Y = 85 $Sendtrap.Location = $System_Drawing_Point $Sendtrap.Name = "Sendtrap" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 109 $Sendtrap.Size = $System_Drawing_Size $Sendtrap.TabIndex = 1 $Sendtrap.Text = "Send test trap" $Sendtrap.UseVisualStyleBackColor = $True $Sendtrap.add_Click($Sendtrap_OnClick) $TestSNMPtrap.Controls.Add($Sendtrap) $SendTrapstatus.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 7 $System_Drawing_Point.Y = 19 $SendTrapstatus.Location = $System_Drawing_Point $SendTrapstatus.Name = "SendTrapstatus" $SendTrapstatus.ReadOnly = $True $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 60 $System_Drawing_Size.Width = 265 $SendTrapstatus.Size = $System_Drawing_Size $SendTrapstatus.TabIndex = 0 $SendTrapstatus.Text = "send test " $TestSNMPtrap.Controls.Add($SendTrapstatus) $CurrentConfL.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 12 $System_Drawing_Point.Y = 218 $CurrentConfL.Location = $System_Drawing_Point $CurrentConfL.Name = "CurrentConfL" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 172 $System_Drawing_Size.Width = 515 $CurrentConfL.Size = $System_Drawing_Size $CurrentConfL.TabIndex = 3 $CurrentConfL.TabStop = $False $CurrentConfL.Text = "Current SNMP Configuration" $vCloudForm.Controls.Add($CurrentConfL) $url.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 7 $System_Drawing_Point.Y = 149 $url.Location = $System_Drawing_Point $url.Name = "url" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 20 $System_Drawing_Size.Width = 120 $url.Size = $System_Drawing_Size $url.TabIndex = 2 $url.TabStop = $True $url.Text = "http://vcloud-lab.com" $CurrentConfL.Controls.Add($url) $CurrentConfB.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 380 $System_Drawing_Point.Y = 144 $CurrentConfB.Location = $System_Drawing_Point $CurrentConfB.Name = "CurrentConfB" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 129 $CurrentConfB.Size = $System_Drawing_Size $CurrentConfB.TabIndex = 1 $CurrentConfB.Text = "Current SNMP conf" $CurrentConfB.UseVisualStyleBackColor = $True $CurrentConfB.add_Click($CurrentConfB_OnClick) $CurrentConfL.Controls.Add($CurrentConfB) $CurrentConfBox.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 7 $System_Drawing_Point.Y = 20 $CurrentConfBox.Location = $System_Drawing_Point $CurrentConfBox.Name = "CurrentConfBox" $CurrentConfBox.ReadOnly = $True $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 118 $System_Drawing_Size.Width = 502 $CurrentConfBox.Size = $System_Drawing_Size $CurrentConfBox.TabIndex = 0 $CurrentConfBox.Text = "snmp conf" $CurrentConfL.Controls.Add($CurrentConfBox) $SetSNMPGroup.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 12 $System_Drawing_Point.Y = 98 $SetSNMPGroup.Location = $System_Drawing_Point $SetSNMPGroup.Name = "groupBox3" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 114 $System_Drawing_Size.Width = 230 $SetSNMPGroup.Size = $System_Drawing_Size $SetSNMPGroup.TabIndex = 2 $SetSNMPGroup.TabStop = $False $SetSNMPGroup.Text = "Set SNMP trap on selected Esxi" $vCloudForm.Controls.Add($SetSNMPGroup) $ConfigureSNMP.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 125 $System_Drawing_Point.Y = 67 $ConfigureSNMP.Location = $System_Drawing_Point $ConfigureSNMP.Name = "ConfigureSNMP" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 41 $System_Drawing_Size.Width = 99 $ConfigureSNMP.Size = $System_Drawing_Size $ConfigureSNMP.TabIndex = 4 $ConfigureSNMP.Text = "Configure SNMP" $ConfigureSNMP.UseVisualStyleBackColor = $True $ConfigureSNMP.add_Click($handler_ConfigureSNMP_Click) $SetSNMPGroup.Controls.Add($ConfigureSNMP) $SNMPFirewall.Checked = $True $SNMPFirewall.CheckState = 1 $SNMPFirewall.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 7 $System_Drawing_Point.Y = 85 $SNMPFirewall.Location = $System_Drawing_Point $SNMPFirewall.Name = "SNMPFirewall" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 24 $System_Drawing_Size.Width = 112 $SNMPFirewall.Size = $System_Drawing_Size $SNMPFirewall.TabIndex = 3 $SNMPFirewall.Text = "Enable Firewall" $SNMPFirewall.UseVisualStyleBackColor = $True $SNMPFirewall.add_CheckedChanged($handler_SNMPFirewall_CheckedChanged) $SetSNMPGroup.Controls.Add($SNMPFirewall) $SNMPService.Checked = $True $SNMPService.CheckState = 1 $SNMPService.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 7 $System_Drawing_Point.Y = 67 $SNMPService.Location = $System_Drawing_Point $SNMPService.Name = "SNMPService" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 24 $System_Drawing_Size.Width = 112 $SNMPService.Size = $System_Drawing_Size $SNMPService.TabIndex = 2 $SNMPService.Text = "Enable Service" $SNMPService.UseVisualStyleBackColor = $True $SNMPService.add_CheckedChanged($handler_checkBox1_CheckedChanged) $SetSNMPGroup.Controls.Add($SNMPService) $SnmpConfBox.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 7 $System_Drawing_Point.Y = 19 $SnmpConfBox.Location = $System_Drawing_Point $SnmpConfBox.Name = "SnmpConfBox" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 147 $SnmpConfBox.Size = $System_Drawing_Size $SnmpConfBox.TabIndex = 1 $SnmpConfBox.Text = 'Server@Port/Community' $SetSNMPGroup.Controls.Add($SnmpConfBox) $ClusterEsxi.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 248 $System_Drawing_Point.Y = 12 $ClusterEsxi.Location = $System_Drawing_Point $ClusterEsxi.Name = "ClusterEsxi" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 79 $System_Drawing_Size.Width = 279 $ClusterEsxi.Size = $System_Drawing_Size $ClusterEsxi.TabIndex = 1 $ClusterEsxi.TabStop = $False $ClusterEsxi.Text = "Clusters and Esxi" $vCloudForm.Controls.Add($ClusterEsxi) $Esxil.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 232 $System_Drawing_Point.Y = 49 $Esxil.Location = $System_Drawing_Point $Esxil.Name = "Esxil" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 20 $System_Drawing_Size.Width = 41 $Esxil.Size = $System_Drawing_Size $Esxil.TabIndex = 3 $Esxil.Text = "Esxi" $ClusterEsxi.Controls.Add($Esxil) $ClusterL.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 232 $System_Drawing_Point.Y = 22 $ClusterL.Location = $System_Drawing_Point $ClusterL.Name = "ClusterL" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 19 $System_Drawing_Size.Width = 41 $ClusterL.Size = $System_Drawing_Size $ClusterL.TabIndex = 2 $ClusterL.Text = "Cluster" $ClusterL.add_Click($handler_label1_Click) $ClusterEsxi.Controls.Add($ClusterL) $EsxiList.DataBindings.DefaultDataSourceUpdateMode = 0 $EsxiList.FormattingEnabled = $True $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 7 $System_Drawing_Point.Y = 47 $EsxiList.Location = $System_Drawing_Point $EsxiList.Name = "EsxiList" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 21 $System_Drawing_Size.Width = 219 $EsxiList.Size = $System_Drawing_Size $EsxiList.TabIndex = 1 $ClusterEsxi.Controls.Add($EsxiList) $ClusterList.DataBindings.DefaultDataSourceUpdateMode = 0 $ClusterList.FormattingEnabled = $True $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 7 $System_Drawing_Point.Y = 20 $ClusterList.Location = $System_Drawing_Point $ClusterList.Name = "ClusterList" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 21 $System_Drawing_Size.Width = 219 $ClusterList.Size = $System_Drawing_Size $ClusterList.TabIndex = 0 $ClusterEsxi.Controls.Add($ClusterList) $GetClusterInfo.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 115 $System_Drawing_Point.Y = 45 $GetClusterInfo.Location = $System_Drawing_Point $GetClusterInfo.Name = "ResetForm" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 105 $GetClusterInfo.Size = $System_Drawing_Size $GetClusterInfo.TabIndex = 2 $GetClusterInfo.Text = "Get-ClusterInfo" $GetClusterInfo.UseVisualStyleBackColor = $True $GetClusterInfo.add_Click($GetClusterInfo_OnClick) $AuthGroup.Controls.Add($GetClusterInfo) $Publicbox.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 7 $System_Drawing_Point.Y = 42 $Publicbox.Location = $System_Drawing_Point $Publicbox.Name = "Publicbox" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 24 $System_Drawing_Size.Width = 147 $Publicbox.Size = $System_Drawing_Size $Publicbox.TabIndex = 5 $Publicbox.Text = "Public" $SetSNMPGroup.Controls.Add($Publicbox) $TargetsLabel.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 154 $System_Drawing_Point.Y = 22 $TargetsLabel.Location = $System_Drawing_Point $TargetsLabel.Name = "TargetsLabel" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 46 $TargetsLabel.Size = $System_Drawing_Size $TargetsLabel.TabIndex = 6 $TargetsLabel.Text = "Targets" $TargetsLabel.add_Click($handler_TargetsLabel_Click) $SetSNMPGroup.Controls.Add($TargetsLabel) $CommunitiesLabel.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 154 $System_Drawing_Point.Y = 45 $CommunitiesLabel.Location = $System_Drawing_Point $CommunitiesLabel.Name = "CommunitiesLabel" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 70 $CommunitiesLabel.Size = $System_Drawing_Size $CommunitiesLabel.TabIndex = 7 $CommunitiesLabel.Text = "Communities" $SetSNMPGroup.Controls.Add($CommunitiesLabel) #endregion Generated Form Code #Save the initial state of the form $InitialFormWindowState = $vCloudForm.WindowState #Init the OnLoad event to correct the initial state of the form $vCloudForm.add_Load($OnLoadForm_StateCorrection) $ClusterEsxi.Controls | Where-Object {$_.Name -match 'EsxiList|ClusterList'} | Foreach {$_.DropDownStyle = 'DropDownList'} function Show-FormOnTop { $vCloudForm.TopMost = $true $vCloudForm.TopMost = $false } Show-FormOnTop function Show-MessageBox { param ( [string]$Message = "Show user friendly Text Message", [string]$Title = 'Title here', [ValidateRange(0,5)] [Int]$Button = 0, [ValidateSet('None','Hand','Error','Stop','Question','Exclamation','Warning','Asterisk','Information')] [string]$Icon = 'Error' ) #Note: $Button is equl to [System.Enum]::GetNames([System.Windows.Forms.MessageBoxButtons]) #Note: $Icon is equl to [System.Enum]::GetNames([System.Windows.Forms.MessageBoxIcon]) $MessageIcon = [System.Windows.Forms.MessageBoxIcon]::$Icon [System.Windows.Forms.MessageBox]::Show($Message,$Title,$Button,$MessageIcon) } Function Confirm-Powercli { $AllModules = Get-Module -ListAvailable VMware.VimAutomation.Core if (!$AllModules) { Show-MessageBox -Message "Install VMware Powercli 6.0 or Latest. `n`nUse either 'Install-Module VMware.VimAutomation.Core' `nor download Powercli from 'http://my.vmware.com'" -Title 'VMware Powercli Missing error' | Out-Null } else { Import-Module VMware.VimAutomation.Core $PowercliVer = Get-Module VMware.VimAutomation.Core $ReqVersion = New-Object System.Version('6.0.0.0') if ($PowercliVer.Version -gt $ReqVersion) { 'Ok' } else { Show-MessageBox -Message "Install VMware Powercli 6.0 or Latest. `n`nUse either 'Install-Module VMware.VimAutomation.Core' `nor download Powercli from 'http://my.vmware.com'" -Title 'Lower version Powercli' | Out-Null } } } function Disconnect-vCenter { try { Disconnect-VIServer * -Confirm:$false -ErrorAction Stop } catch { #Show-MessageBox -Message $error[0].Exception.Message -Title 'Error Connecting vCenter' | Out-Null } } $vCenterServerName = $vCenterName.Text function Disable-Controls { if ($global:DefaultViServer -eq $null) { $GetClusterInfo.Enabled = $False } else { $GetClusterInfo.Enabled = $true } if ($GetClusterInfo.Enabled -eq $False) { $ClusterEsxi.Enabled = $False } else { $ClusterEsxi.Enabled = $true } $CurrentConfControlInfo = $CurrentConfL.Controls | Where-Object -FilterScript {$_.Name -ne 'url'} foreach ($CurrentConfControl in $CurrentConfControlInfo ) { $CurrentConfControl.Enabled = $False } $SetSNMPGroup.Enabled = $False $TestSNMPtrap.Enabled = $False } Disable-Controls function Enable-Controls { if ($GetClusterInfo.Enabled -eq $true) { $ClusterEsxi.Enabled = $true $CurrentConfL.Enabled = $true $TestSNMPtrap.Enabled = $true $SetSNMPGroup.Enabled = $true $CurrentConfControlInfo = $CurrentConfL.Controls | Where-Object -FilterScript {$_.Name -ne 'url'} foreach ($CurrentConfControl in $CurrentConfControlInfo ) { $CurrentConfControl.Enabled = $true } } } Function Connect-vCenter { param ( [parameter(Position=0,ValueFromPipeline=$true)] [string]$vCenterServerName = $vCenterName.Text ) Confirm-Powercli Show-FormOnTop if ($Global:DefaultVIServer -ne $null) { Disconnect-vCenter } if (($vCenterServer.Text -eq $vCenterNameWaterMark) -or ($vCenterServer.Text -eq '')) { #[System.Windows.Forms.MessageBox]::Show("Please type valid Domain\Account", "Textbox empty") Show-MessageBox -Message "Please type valid vCenter server name" -Title 'vCenter Server Name' | Out-Null $status2.Text = 'Type Valid ComputerName' } else { try { $status1.Value = 30 $cred = Get-Credential $status1.Value = 60 Show-FormOnTop Connect-VIServer $vCenterServerName -Credential $Cred -ErrorAction Stop | Out-Null $status1.Value = 100 $status2.Text = "Connected to $vCenterServerName With $($Cred.UserName)" $GetClusterInfo.Enabled = $true } catch { Show-FormOnTop Show-MessageBox -Message $error[0].Exception.Message -Title 'Error Connecting vCenter' | Out-Null $status2.Text = "Failed $($error[0].Exception.Message)" } } Show-FormOnTop } $LoginvCenter.Add_Click({ Connect-vCenter }) function clear-Boxes { $CurrentConfBox.Text = '' $SendTrapstatus.Text = '' } function Get-SelectedEsxi { try { $Status1.Value = 0 $Script:VMhostEsxi = $Script:EsxiInfo | Where-Object {$_.Name -eq $EsxiList.SelectedItem} $Script:Esxicli = $Script:VMhostEsxi | Get-EsxCli -V2 -ErrorAction Stop $Status1.Value = 100 } catch { Show-MessageBox -Message 'Selected Esxi should be v6.x and above, Latest esxcli version 2 not supported' -Title 'esxcli v2 not supported' Disable-Controls } } function Get-EsxiInfo { $Script:FixedCluster = $ClusterList.SelectedItem if ($ClusterList.SelectedItem -ne 'No Cluster Found' -or $ClusterList.SelectedItem -ne '') { $Script:EsxiInfo = Get-Cluster $ClusterList.SelectedItem | Get-VMHost | Where-Object -FilterScript {$_.ConnectionState -eq 'Connected'} $EsxiList.Items.Clear() if ($Script:EsxiInfo -ne $null) { $Status1.Value = 55 $EsxiList.Items.AddRange($Script:EsxiInfo.Name) $EsxiList.Text = $EsxiList.Items[0] #Get-SelectedEsxi $Status1.Value = 100 $status2.Text = 'Esxi list populated, choose one esxi server' Enable-Controls } else { $Status1.Value = 0 $EsxiList.Items.AddRange('No Esxi found in cluster') $EsxiList.Text = 'No Esxi found in cluster' $status2.Text = 'No Esxi found in cluster, Select another cluster' Disable-Controls } } else { $status2.Text = 'Select a cluster which has Esxi servers' } } function Get-ClusterInfo { $script:ClusterInfo = Get-Cluster $Status1.Value = 30 if ($script:ClusterInfo -ne '') { $ClusterList.Items.AddRange($script:ClusterInfo.Name) $ClusterList.Text = $ClusterList.Items[0] $status2.Text = 'Cluster list populated, choose one esxi server' Get-EsxiInfo #Enable-Controls } else { $Status1.Value = 0 $ClusterList.Text = 'No Cluster Found' $status2.Text = 'No cluster found in vCenter server' Disable-Controls } } $GetClusterInfo.Add_Click({ $ClusterEsxi.Controls | Where-Object {$_.Name -match 'EsxiList|ClusterList'} | Foreach {$_.Items.Clear() = $null} $Status1.Value = 0 Get-ClusterInfo }) $ClusterList.Add_SelectedIndexChanged({ if ($script:ClusterInfo -ne $ClusterList.SelectedItem) { Get-EsxiInfo #Get-SelectedEsxi } }) $Sendtrap.Add_Click({ Get-SelectedEsxi try { $SendTrapstatus.Text = ($Script:Esxicli.system.snmp.test.Invoke().comments | Out-String).Trim() } catch { $SendTrapstatus.Text = $Error[0].Exception.Message } }) $CurrentConfB.Add_Click({ Get-SelectedEsxi $CurrentConfBox.Text = ($Script:Esxicli.system.snmp.get.Invoke() | Out-String).Trim() #$CurrentConfBox.AppendText($Script:VMhostEsxi.Name) }) function Set-SNMPConfiguration { Get-SelectedEsxi Switch ($SNMPService.Enabled) { $True { $NewSNMPServiceState = Get-VMHostService -VMHost $EsxiList.SelectedItem | Where-Object {$_.Key -eq 'snmpd'} | Select-Object Label, Policy, Running } $False { [void]$Script:esxicli.system.snmp.set.Invoke(@{enable=$true}) $NewSNMPServiceState = Get-VMHostService -VMHost $EsxiList.SelectedItem | Where-Object {$_.Key -eq 'snmpd'} | Start-VMHostService | Set-VMHostService -Policy On | Select-Object Label, Policy, Running } } $CurrentConfBox.Text = "{0} Service {0}`n" -f $('-'*15) $CurrentConfBox.AppendText("$(($NewSNMPServiceState | Out-String).trim())`n`n") Switch ($SNMPFirewall.Enabled) { $True { $NewSNMPfirewallStatus = Get-VMHostService -VMHost $EsxiList.SelectedItem | Where-Object -FilterScript {$_.Key -eq 'snmpd'} | select Key, Label, Policy, Running } $False { $NewSNMPfirewallstatus = Get-VMHostService -VMHost $EsxiList.SelectedItem | Where-Object -FilterScript {$_.Key -eq 'snmpd'} | Set-VMHostService -Policy On | Start-VMHostService -Confirm:$False | select Key, Label, Policy, Running #$Configurefirewall = $Script:esxicli.network.firewall.ruleset.set.CreateArgs() #$Configurefirewall.rulesetid = 'snmp' #$Configurefirewall.enabled = $true #[void]$Script:esxicli.network.firewall.ruleset.set.invoke($Configurefirewall) #$NewSNMPfirewallStatus = Get-VMHostService -VMHost $EsxiList.SelectedItem | Where-Object -FilterScript {$_.Key -eq 'snmpd'} } } $CurrentConfBox.AppendText("{0} Firewall {0}`n" -f $('-'*15)) $CurrentConfBox.AppendText("$(($NewSNMPfirewallStatus | Out-String).trim())`n`n") $Script:esxicli.system.snmp.set.Invoke(@{enable=$true}) if ($SnmpConfBox.Text -eq 'Server@Port/Community' -or $SnmpConfBox.Text -eq '') { Show-MessageBox -Title 'Incorrect SNMP configuration' -Message 'Choose correct SNMP server, Port and community string' $status2.Text = 'Incorrect SNMP configuration' } else { $SetSNMPTarget = $Script:esxicli.system.snmp.set.CreateArgs() $SetSNMPTarget.targets = $SnmpConfBox.Text $SetSNMPTarget.communities = $Publicbox.Text $esxicli.system.snmp.set.Invoke($SetSNMPTarget) | Out-Null $NewSNMPConf = ($Script:Esxicli.system.snmp.get.Invoke() | Out-String).Trim() $CurrentConfBox.AppendText("{0} Configuration {0}`n" -f $('-'*15)) $CurrentConfBox.AppendText($NewSNMPConf) $status2.Text = 'SNMP configuration completed' } } $ConfigureSNMP.Add_Click({Set-SNMPConfiguration}) $logoffvCenter.Add_Click({ Disable-Controls Disconnect-vCenter }) #$ConfigureSNMP #$esxcli = Get-VMHost esxi001.vcloud-lab.com | Get-EsxCli -V2 #$esxcli.system.snmp.get.Invoke() #$esxcli.system.snmp.test.Invoke().comments #$SNMPTarget = $esxcli.system.snmp.set.CreateArgs() #$SNMPTarget.targets = '192.168.34.1@1621/public1' #$esxcli.system.snmp.set.Invoke($SNMPTarget) | Out-Null #Get-VMHostService #Show the Form $vCloudForm.ShowDialog()| Out-Null } #End Function #Call the Function GenerateForm #$ErrorActionPreference = $CurretSettings

Useful Articles

VMWARE SECURITY BEST PRACTICES: POWERCLI ENABLE OR DISABLE ESXI SSH

vSphere ESXi security best practices: Time configuration - (NTP) Network Time Protocol

Configure syslog on VMware ESXi hosts: VMware best practices