{"id":455,"date":"2012-01-14T23:18:59","date_gmt":"2012-01-15T04:18:59","guid":{"rendered":"http:\/\/www.anthonyreinke.com\/?p=455"},"modified":"2018-05-07T21:15:05","modified_gmt":"2018-05-08T03:15:05","slug":"installing-snmp-through-the-command-line","status":"publish","type":"post","link":"https:\/\/anthonyreinke.com\/index.php\/2012\/01\/14\/installing-snmp-through-the-command-line\/","title":{"rendered":"Installing SNMP through the Command Line"},"content":{"rendered":"<p>I needed a way to mass install SNMP to the servers in my environment. \u00a0The problem I was having was Microsoft Windows Server 2003 needing files from the CD. \u00a0We don&#8217;t copy the i386 directory from the CD for two reasons. \u00a0We store the files on the network and drive space is limit on a lot of servers. \u00a0The batch script will check if the server is 2003. \u00a0If it is 2003, it will point the install cd to a network path or a local path. \u00a0Next it builds the \u00a0unattended install file. \u00a0Once the file is written, the system will add the SNMP feature per the\u00a0unattended\u00a0file. \u00a0After SNMP is installed, the registry keys are set for the SNMP community strings. \u00a0Lastly the script removes the temporary files it created.<\/p>\n<p>Use this script in combination to PSTools&#8217; PSExec and you can mass install. \u00a0Create a list of systems you want to install this on and call it hosts.txt. \u00a0Each server needs to be on it&#8217;s own line and it is best to use the fully qualified name or IP Address. \u00a0Copy the hosts.txt and installsnmp.bat file in to your PSTools directory and run the following command:<\/p>\n<pre><span style=\"color: #339966;\">PsExec.exe @hosts.txt -s -c installsnmp.bat<\/span><\/pre>\n<p><a href=\"http:\/\/www.anthonyreinke.com\/wp-content\/uploads\/2012\/01\/installsnmp.txt\">Download the Install SNMP Batch File, just rename to a .bat file.<\/a><\/p>\n<p>&nbsp;<\/p>\n<pre><\/pre>\n<pre><span style=\"color: #339966;\">@echo off<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">echo %COMPUTERNAME% Started &gt;&gt; \\\\server\\share\\SNMP\\SNMPInstall.txt<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">REM Detect if the system is Windows Server 2003\r\nsysteminfo | find \"2003\" &gt; nul\r\nif %ERRORLEVEL% == 0 goto 2003<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">REM Detect if the system is Windows XP\r\nsysteminfo | find \"XP Pro\" &gt; nul\r\nif %ERRORLEVEL% == 0 goto XPPro<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">REM If the system is Windows Vista, Windows Server 2008, or higher, \r\nREM they have the required files built in.\r\ngoto SNMP<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">:2003\r\nREM If Windows 2003, set the path to the i386 directory\r\nREM Note: The path needs to be one level above the i386 directory\r\nREM Example: if the path is \\\\server\\share\\windows2003\\i386\\ then\r\nREM the path would be \\\\server\\share\\windows2003\\\r\nREM Note that the you need both a 32bit and 64bit versions<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">if (%PROCESSOR_ARCHITECTURE%) == (AMD64) (\r\n(\r\necho Windows Registry Editor Version 5.00\r\necho.\r\necho [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup]\r\necho \"SourcePath\"=\"\\\\\\\\server\\\\share\\\\Extracted\\\\Win2003x64\\\\\"\r\necho \"ServicePackSourcePath\"=\"\\\\\\\\server\\\\share\\\\Extracted\\\\Win2003x64\\\\\"\r\n) &gt; %temp%\\setW2003Path.reg\r\n) ELSE IF (%PROCESSOR_ARCHITECTURE%) == (x86)\r\n(\r\necho Windows Registry Editor Version 5.00\r\necho.\r\necho [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup]\r\necho \"SourcePath\"=\"\\\\\\\\server\\\\share\\\\Extracted\\\\Win2003\\\\\"\r\necho \"ServicePackSourcePath\"=\"\\\\\\\\server\\\\share\\\\Extracted\\\\Win2003\\\\\"\r\n) &gt; %temp%\\setW2003Path.reg\r\n)<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">REM Installing the created Registry File\r\nregedit \/s \/q %temp%\\setW2003Path.reg<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">goto SNMP<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">:XPPro\r\nREM If Windows XP Professional, set the path to the i386 directory\r\nREM Note: The path needs to be one level above the i386 directory\r\nREM Example: if the path is \\\\server\\share\\windowsXP\\i386\\ then\r\nREM the path would be \\\\server\\share\\windowsXP\\\r\nif (%PROCESSOR_ARCHITECTURE%) == (AMD64) (\r\n(\r\necho Windows Registry Editor Version 5.00\r\necho.\r\necho [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup]\r\necho \"SourcePath\"=\"\\\\\\\\server\\\\share\\\\Extracted\\\\XPProx64\\\\\"\r\necho \"ServicePackSourcePath\"=\"\\\\\\\\server\\\\share\\\\Extracted\\\\XPProx64\\\\\"\r\n) &gt; %temp%\\setXPProPath.reg\r\n) ELSE IF (%PROCESSOR_ARCHITECTURE%) == (x86)\r\n(\r\necho Windows Registry Editor Version 5.00\r\necho.\r\necho [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup]\r\necho \"SourcePath\"=\"\\\\\\\\server\\\\share\\\\Extracted\\\\XPPro\\\\\"\r\necho \"ServicePackSourcePath\"=\"\\\\\\\\server\\\\share\\\\Extracted\\\\XPPro\\\\\"\r\n) &gt; %temp%\\setXPProPath.reg\r\n)<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">REM Installing the created Registry File\r\nregedit \/s \/q %temp%\\setXPProPath.reg.reg<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">goto SNMP<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">:SNMP\r\nREM Building the Unattended Install<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">(\r\necho ;SetupMgrTag\r\necho [NetOptionalComponents]\r\necho SNMP=1\r\necho [SNMP]\r\necho Any_Host=YES\r\n) &gt; %temp%\\snmp.txt<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">REM Installing the SNMP application with the Unattended Install<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">sysocmgr \/i:%windir%\\inf\\sysoc.inf \/u:%temp%\\snmp.txt<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">goto Strings<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">:2008\r\nREM Since 2008 stopped using the sysocmgr.exe to install features, in Vista and higher\r\nREM you need to use the servermanagercmd.exe to add features. A great list of the \r\nREM features and their command line install string is at:\r\nREM http:\/\/www.techrepublic.com\/blog\/datacenter\/install-windows-server-2008-features-with-servermanagercmd\/294<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">servermanagercmd.exe -install SNMP-Services<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">goto Strings<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">:Strings<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">REM Removing the public string\r\n(\r\necho Windows Registry Editor Version 5.00\r\necho.\r\necho [-HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Services\\SNMP\\Parameters\\ValidCommunities]<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">REM Setting the SNMP strings\r\necho.\r\necho [HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Services\\SNMP\\Parameters\\RFC1156Agent]\r\necho \"sysContact\"=\"Server Administrators\"\r\necho \"sysLocation\"=\"Server Room\"\r\necho \"sysServices\"=dword:0000004f\r\necho.\r\necho [HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Services\\SNMP\\Parameters\\ValidCommunities]\r\necho \"readonly\"=dword:00000004\r\necho \"readwrite\"=dword:00000008\r\n) &gt; %temp%\\setupsnmp.reg<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">REM Installing the created Registry File<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">regedit \/s \/q %temp%\\setupsnmp.reg<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<pre><span style=\"color: #339966;\">REM Cleaning Up<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\u00a0<\/span><\/pre>\n<p><span style=\"color: #339966;\">IF EXIST %temp%\\setupsnmp.reg del %temp%\\setupsnmp.reg<\/span><br \/>\n<span style=\"color: #339966;\"> IF EXIST %temp%\\setW2003Path.reg del %temp%\\setW2003Path.reg<\/span><br \/>\n<span style=\"color: #339966;\"> IF EXIST %temp%\\setXPProPath.reg.reg del %temp%\\setXPProPath.reg.reg<\/span><br \/>\n<span style=\"color: #339966;\"> IF EXIST %temp%\\snmp.txt del %temp%\\snmp.txt<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #339966;\">echo %COMPUTERNAME% Complete &gt;&gt; \\\\server\\share\\SNMP\\SNMPInstall.txt<\/span><\/p>\n<p><span style=\"color: #00ff00;\"><br \/>\n<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I needed a way to mass install SNMP to the servers in my environment. \u00a0The problem I was having was Microsoft Windows Server 2003 needing files from the CD. \u00a0We don&#8217;t copy the i386 directory from the CD for two reasons. \u00a0We store the files on the network and drive space is limit on a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-455","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/anthonyreinke.com\/index.php\/wp-json\/wp\/v2\/posts\/455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/anthonyreinke.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anthonyreinke.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anthonyreinke.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/anthonyreinke.com\/index.php\/wp-json\/wp\/v2\/comments?post=455"}],"version-history":[{"count":2,"href":"https:\/\/anthonyreinke.com\/index.php\/wp-json\/wp\/v2\/posts\/455\/revisions"}],"predecessor-version":[{"id":12413,"href":"https:\/\/anthonyreinke.com\/index.php\/wp-json\/wp\/v2\/posts\/455\/revisions\/12413"}],"wp:attachment":[{"href":"https:\/\/anthonyreinke.com\/index.php\/wp-json\/wp\/v2\/media?parent=455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anthonyreinke.com\/index.php\/wp-json\/wp\/v2\/categories?post=455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anthonyreinke.com\/index.php\/wp-json\/wp\/v2\/tags?post=455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}