Posts tagged Script

Hyper-V from cmd

hero_hyper-vHyper-V, a key feature of Windows Server 2008, has now released to manufacturing (RTM) and is available for deployment into production environments. With help of ServerManagerCMD.exe I will install the Hyer-V role.

 

What is ServerManagerCMD.exe?

Server Manager in Windows Server 2008 provides a single source for managing a server’s identity and system information, displaying server status, identifying problems with server role configuration, and managing all roles installed on the server.

ServerManagerCMD is powerful tool and within one command line you can install the Hyper-V role. Make sure you installed the Windows 2008 RTM version and updated your system with KB950050.

image

With ServerManagerCMD.exe you will be able to install all those roles:

Active Directory Certificate Services
Active Directory Domain Services
Active Directory Federation Services
Active Directory Lightweight Directory Services
Active Directory Rights Management Services
Application Server
Availability and Scalability
DHCP Server
DNS Server
Fax Server
File Services
Hyper-V
Network Policy and Access Services
Print Services
Streaming Media Services
Terminal Services
Troubleshooting
UDDI Services
Web Server
Windows Deployment Services

Finally we get a single command line tool for this administrative task. I hate having different text files and run the cmd batch scripts.

Related links:

ESX: esxcfg-vswitch and special vlan switch

If you need to create 5 or more of Virtual Port groups on a vSwtich and you don’t want to use the VI client than logon on the service console and run the commands below.

For creating a new Virtual Port Group use:

esxcfg-vswitch -A NAME-TO-GIVE vSwitch0

Assigning a special VLAN to this a Virtual Port Group:

esxcfg-vswitch -v VLANID -p PORTGROUP vSwitch0

With these two simple commands I was able to push my sh script and create same “Networking” configuration on dozen of my ESX servers.

[root@ESX-02 root]# esxcfg-vswitch -A VLAN282 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -A VLAN283 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -A VLAN284 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -A VLAN285 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -A VLAN299 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -A VLAN220 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -v 282 -p VLAN282 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -v 283 -p VLAN283 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -v 284 -p VLAN284 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -v 285 -p VLAN285 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -v 299 -p VLAN299 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -v 220 -p VLAN220 vSwitch0

esxcfg-vswitch [options] [vswitch[:ports]]

  -a|–add              Add a new virtual switch.

  -d|–delete           Delete the virtual switch.

  -l|–list             List all the virtual switches.

  -L|–link=pnic        Set pnic as an uplink for the vswitch.

  -U|–unlink=pnic      Remove pnic from the uplinks for the vswitch.

  -M|–add-pg-uplink    Add an uplink to the list of uplinks for a portgroup

  -N|–del-pg-uplink    Delete an uplink from the list of uplinks for a portgroup

  -p|–pg=portgroup     Specify a portgroup for operation

                        Use ALL to set VLAN IDs on all portgroups

  -v|–vlan=id          Set vlan id for portgroup specified by -p

                        0 would disable the vlan

  -c|–check            Check to see if a virtual switch exists.

                        Program outputs a 1 if it exists, 0 otherwise.

  -A|–add-pg=name      Add a new portgroup to the virtual switch.

  -D|–del-pg=name      Delete the portgroup from the virtual switch.

  -C|–check-pg=name    Check to see if a portgroup exists.  Program

                        outputs a 1 if it exists, 0 otherwise.

  -B|–set-cdp          Set the CDP status for a given virtual switch.

                        To set pass one of “down”, “listen”, “advertise”, “both”.

  -b|–get-cdp          Print the current CDP setting for this switch.

  -m|–mtu=MTU          Set MTU for the vswitch.

  -r|–restore          Restore all virtual switches from the configuration file

                        (FOR INTERNAL USE ONLY).

  -h|–help             Show this message.

Windows Active Directory DCpromo answer file

The following example will help you to quickly provision an Active Directory domain in vm or other lab environments. The provision of domain controller can be controlled and reproduced same way as before.  Copy the text below and create new text file named ad.txt.  

[DCInstall]
AdministratorPassword =P@SSWORD1
CreateOrJoin = Create
DomainNetBiosName = 70-296
NewDomainDNSName = 70-296.net
RebootOnSuccess = Yes
ReplicaOrNewDomain = Domain
SiteName = “Default-First-Site”
InstallDNS=yes
ConfirmGc=Yes
TreeOrChild = Tree
UserName=Administrator
Password=P@SSWORD1

Review the local administrator password and open a cmd shell on your Windows Server. Run dcpromo /answer:ad.txt. In the example answer file I automatically install the DNS server; make sure the Windows Server source cd-rom is available locally or in a cd drive.

For more options go to http://support.microsoft.com/kb/223757/en-us or  http://www.petri.co.il/unattended_installation_of_active_directory.htm.

After the reboot and logon with Domain Administrator account I verify the installation with ADUC (dsa.msc) console.

image

The Active Directory domain was successfully installed. Using the answer file I am able to redo my lab environments and prepare myself for production deployments.

Dell PowerEdge CPU check for Intel VT

Last year I installed three Dell PowerEdge 1950 1U servers and since than I used them in production as VMWare Server hosts. Couple times when creating and migrating the guest machines I received a warning that my CPU was VT capable but not enabled. To enable this option reboot the Dell server, hit F2 to enter the BIOS and change the Intel VT Virtualization Technology CPU setting. Each month there is a scheduled maintenance and if there is a security update than it will be installed and server reboot, but than I will need to be there and enter the BIOS by console or DRAC console. For that reason I created two scripts to check the CPU bios setting and if required execute the second cmd script to enable the VT option.

Please make sure the Dell OpenManage software is installed. The commands available for Windows and ESX operating systems.

@echo off
REM Ivan Versluis / Ivan1980(at)networknet.nl / Dell PowerEdge Intel VT check
omreport chassis biossetup & omreport chassis processors
pause

image 

@echo off
REM Ivan Versluis / Ivan1980(at)networknet.nl / Dell PowerEdge Intel VT enable
omconfig chassis biossetup attribute=cpuvt setting=enabled
omconfig chassis biossetup attribute=dbs setting=enable
pause

image

For more information check out this document.  The enable script has been executed and I only need to get new security updates for this month. I’ve seen no security update  information from Microsoft last days and I will need to wait until next WSUS assigned patches will reboot the servers.

VMWare Player cmd startup script

Did you ever tried to automate the process of having a script or shortcut to automatically start a virtual guest with VMWare Player? After you login you can start VMWare Player and locate the virtual machine or click the recent one but still you need to control this process. Maybe you want to start the virtual machine at system startup with Scheduled Tasks or instruct a user to click on a specific shortcut for a pre-created virtual machine he needs to test.

I created a small script which can used for this process. Create new file in notepad and paste the commands below. Make sure the VMWare Player installation path is correct and the location of your VMWare guest.

@Echo off

REM VMWare Player cmd script for virtual guest startup

REM Ivan Versluis @ Networknet.nl

REM Email: Ivan.Versluis@networknet.nl

REM Date: 29/01/2008

"C:\Program Files\VMware\VMware Player\vmplayer.exe" "C:\VMWareGuests\Server\Windows Server 2003 Standard Edition.vmx"

The result ;)

image

Install Windows Server 2003 DHCP Server Service with Script

Running the VMNet8 NAT network in VMWare Workstation does not provide me the granular control how the DHCP server should deal with different DHCP clients and options I want to see in my lab environment. As sysadmin I like to script things and re-use the code next time I will need to it.

How to install the DHCP service from script?

  • Create new file named c:\dhcp_server.txt

[NetOptionalComponents]

DHCPServer =1

  • Save the file and open a cmd box.
  • Execute sysocmgr /i:%windir%\inf\sysoc.inf /u:c:\dhcp_server.txt

image 

For additional components go to here.