Category Archives: Uncategorized

Batch Script Add Windows Users using Netsh

The following batch script will add a group of users to Windows, set no password, and require a password change at first logon.

@echo off
setlocal enabledelayedexpansion

set user1=John Q. Smith
set user2=Jane Doe
set user3=Joe Montana
set user4=Alicia Silverstone

set users=(user1 user2 user3 user4 user5 user6)

for %%u in %users% do (
  echo net user %%u /logonpasswordchg:yes /fullname:"!%%u!" /add
)

Monitor ESXi Free using SNMP

ESXi 4.1 and 5.0 Enable SNMP

SSH to host and edit the SNMP.XML file:

vi /etc/vmware/snmp.xml

Make the following changes:

<config>
<snmpSettings>
<enable>true</enable>
<communities>public</communities>
<targets>192.168.1.100@public</targets>
</snmpSettings>
</config>

Restart management agents with the following command:

/etc/init.d/hostd restart

On ESXi 5.1 and 5.5 enable SNMP

SSH to host and run the following command:

esxcli system snmp set --communities=public --enable=yes --targets=192.168.1.100/public

Test SNMP trap

vicfg-snmp --server <ESXiServerIP> --username root --password <Password> --test

Reviewing the SNMP configuration

When I look at my SNMP configuration using vCLI (once again, this is a read operation so I can use vCLI), I see the following.

vi-admin@vma:~> vicfg-snmp --server <ESXiServerIP> --username root --password <Password> -s

Current SNMP agent settings:
Enabled : 1
UDP port : 161

Communities :
public

Notification targets :
192.168.1.100@162/public

Options :
EnvEventSource=indications

Use netsh to set interface IP static or dhcp

Get Configuration Info

Using the command below, you can gather information on the adapter’s current configuration. Make note of the connection name since that is what is used to in the configuration command further down.

netsh interface ip show config
Figure 1 - Example of netsh interface ip show config

Figure 1 – Example of netsh interface ip show config

You can see the existing configuration with the following command.

netsh interface ip dump
2016-05-05_113938

Figure 2 – Example of netsh interface ip dump

Set Interface DHCP

To set interface address as DHCP, issue the following.  Change the items highlighted in Red to suite your environment.

Note:  Use the above command (netsh interface ip dump) to figure out which interface you need to use.  Default is “Local Area Connection” but many environments will differ.  Match the interface= portion and supply that in the Red sections below.  I’m leaving the default of “Local Area Connection” but you can see that my interface would be “Ethernet”.

2016-05-05_113938-2

Figure 3 – Determine the interface name to use when configuring the interface via netsh

netsh interface ip set address "Local Area Connection" dhcp

You also can set the DNS statically or via DHCP as well.

netsh interface ip set dns "Local Area Connection" 8.8.4.4

Set a secondary DNS server:

netsh interface ip set dns "Local Area Connection" 8.8.4.4 index=2

Set Interface Static

Set the interface with a static address. Change the items in Red to suite your environment.

netsh interface ip set address "Local Area Connection" static ipaddr subnetmask gateway metric

Set the DNS server statically.

netsh interface ip set dns "Local Area Connection" 8.8.4.4

Set a secondary DNS server:

netsh interface ip set dns "Local Area Connection" 8.8.4.4 index=2