In a previous post I talked about setting up Windows Server 2008 Enterprise Edition 64-bit to be a Hyper-V platform, Microsoft’s recommendation is for the Virtual Machine host to be running Server Core – dig out your old PC-DOS or MS-DOS commands then apply 20+ years of updates 😉
Server Core is all about the command line and scripting and I was recently lucky enough to have attended a Microsoft Hyper-V RDP bootcamp in which we covered Server Core deployments, this and having trawled various blog posts but not being able to find a single source for common Hyper-V server core setup commands made me want to document the setup scripts I used to allow quick and easy replication and, of course, for all dev environments – frequent rebuild!
These are listed in the order I would perform them to either minimise security or network ‘steps’ (such as name registration order):
To enable Automatic Updates and force an immediate update (apparently you can also define a schedule – for non-managed servers we only allow Saturday at 03:00)
[sc-enableAU.cmd]
cscript windowssystem32scregedit.wsf /au 4
net stop wuauserv
net start wuauserv
wuauclt /detectnow
To enable Terminal Services access
[sc-enableTS.cmd]
cscript windowssystem32scregedit.wsf /ar 0
cscript windowssystem32scregedit.wsf /cs 1
(for help on what commands are available via scregedit type cscript windowssystem32scregedit.wsf /?)
To rename the local computer name
[sc-renamecomputer.cmd]
hostname
netdom renamecomputer <old_host_name> /newname:<new_host_name>
rem – a shutdown /r /t 0 will be needed to restart the computer for the change to be applied
To change the workgroup name
[sc-changeWGroup.cmd]
rem usage sc-changeWGroup <host_name> <workgroup_name>
hostname
wmic computersystemwhere name=”%1″ call joindomainorworkgroup name=”%2″
rem – a shutdown /r /t 0 will be needed to restart the computer for the change to be applied
To list the status of Hyper-V and install it (assumes any pre-req patches such as RC0)
[sc-enableHV.cmd]
oclist | find “Hyper-V”
ocsetup Microsoft-Hyper-V
To rename the new virtual switch interface from the default Local Area Connection 3
[sc-renameLAN3.cmd]
netsh interface set interface name = “Local Area Connection 3” newname = “Local Area Connection – Virtual”
Script to set IP, mask, G/W, & DNS servers
[sc-setIP.cmd]
rem changes ip address by script
rem usage – sc-setIP <ip address> <subnet mask> <gateway> <dns1> <dns2>
netsh interface ipv4 set address name=”Local Area Connection – Virtual” source=static address=%1 mask=%2 gateway=%3
netsh interface ipv4 add dnsserver name=”Local Area Connection – Virtual” address=%4 index=1
netsh interface ipv4 add dnsserver name=”Local Area Connection – Virtual” address=%5 index=2
netsh interface ipv4 show config | more
To open WMI for Hyper-V remote administration
[sc-openWMI.cmd]
winrm quickconfig
netsh advfirewall firewall set rule group=”Windows Management Instrumentation (WMI)” new enable=yes
net localgroup “Distributed COM Users” /add Admin-TFCSupport
or to open a WorkGroup server for full remote administration…
[sc-openRA-WGroup.cmd]
netsh advfirewall firewall set rule group=“Remote Administration” new enable=yes
[sc-setIP.cmd]
rem changes ip address by script
rem usage – sc-setIP <ip address> <subnet mask> <gateway> <dns1> <dns2>
netsh interface ipv4 set address name=”Local Area Connection” source=static address=%1 mask=%2 gateway=%3
netsh interface ipv4 add dnsserver name=”Local Area Connection” address=%4 index=1
netsh interface ipv4 add dnsserver name=”Local Area Connection” address=%5 index=2
netsh interface ipv4 show config | more
[sc-enableICMP]
netsh firewall set icmpsetting 8
(or to simply disable the entire firewall… netsh firewall set opmode disable)
[sc-setNTP.cmd]
w32tm /configure /manualpeerlist:pool.ntp.org,212.111.32.110,0×8 /syncfromflags:MANUAL
net stop w32time
net start w32time
w32tm /resync /nowait
Of course, a lot of these commands are not just specific to Server Core but can be also run on full versions of WS2008, the new Hyper-V Server soon to be launched, or indeed Vista.
One last great command line line tool to confirm many of the outcomes and changes executed by the commands detailed here is ‘systeminfo’ – try it!
update… two excellent resources that expand way more than I have time to are:
http://blogs.technet.com/server_core/
http://msmvps.com/blogs/ad/archive/2008/09/18/admin-s-guide-to-server-core-commands.aspx