Commands for Windows Server Core & Hyper-V Core Server

For some KTSI projects I have been working a lot with Windows Server Core or Hyper-V Server. Now I had to do a lot of automation, so I made this little connection of commands. If you configure the server manually you can do the most important things with the sconfig utility.

Windows Server Core

Networking

Set Hostname

netdom renamecomputer %COMPUTERNAME% /NewName:<NewComputerName> 

Join Domain

netdom join %COMPUTERNAME% /domain:<DomainName> /userd:<UserName> /passwordd:*

Remove Domain

netdom remove

Rename Network Interface

netsh interface set interface name=”old name” newname=”new name”

Configure IP Address

netsh interface ipv4 set address name=”<Interface Name>” source=static address=<IPAddress> mask=<SubnetMask> gateway=<DefaultGateway>

Configure DNS Servers

netsh interface ipv4 add dnsserver name=”<Interface Name>” address=<DNS Server IP> index=1

Disable Firewall (not recommended)

netsh advfirewall set allprofiles state off

 

Remoting

Enable PowerShell Remoting

Enable-PSRemoting

Enable Remotedesktop

netsh advfirewall firewall set rule group=”remote desktop” new enable=yes

Enable Remote Administration

advfirewall firewall set rule group=”Remote Administration” new enable=yes

Enable Remote Firewall Administration

netsh advfirewall firewall set rule group=”Windows Firewall Remote Management” new enable=yes

Enable ICMP (Ping)

netsh firewall set icmpsetting 8

Enable Remote Disk Management

netsh advfirewall firewall set rule group=”Remote Volume Management” new enable=yes

 

Licensing

Enter License key

slmgr.vbs -ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

Activate Windows

slmgr.vbs -ato

 

Windows Update

Enable automatic updates

cscript C:'Windows'System32'Scregedit.wsf /au 4

Disable automatic updates

cscript C:'Windows'System32'Scregedit.wsf /au 1

 

Roles & Features

Get availibale features & roles

Dism /online /get-features /format:table

Enable feature & roles

Dism /online /enable-feature /featurename:<featurename>

 

Basics

Change Administrator password

net user administrator *

Restart Computer

shutdown /r /t 0

Logoff

logoff

More information about Server Core: TechNet

Check NTFS Version

If you need to know which version of NTFS you are using you can do that with the fsutil.exe and the following command.

In my case I am testing my C:\ drive:

fsutil fsinfo ntfsinfo c:

fsutil

More on NTFS Versions on wikipedia.

Quick nslookup Guide

nslookup help

This is a quick note how to use nslookup.exe.

Start nslookup and check for domain

C:> nslookup
Default Server:  ns1.corp.pepsi.local
Addresse:  10.10.20.1
> thomasmaurer.ch
Default Server: ns1.corp.pepsi.local
Addresse: 10.10.20.1

Name:    thomasmaurer.ch
Address:  217.26.52.30
>

Change Nameserver for search querys

> server ns2.corp.pepsi.local
Default Server: ns2.corp.pepsi.local
Addresse: 10.10.20.2
>

Set a query type (ex. A,AAAA,A+AAAA,ANY,CNAME,MX,NS,PTR,SOA,SRV)

> set type=mx
> thomasmaurer.ch
Server: ns2.corp.pepsi.local
Address:  10.10.20.2

thomasmaurer.ch MX preference = 10, mail exchanger = mx2.mail.genotec.ch
thomasmaurer.ch MX preference = 10, mail exchanger = mx1.mail.genotec.ch
mx1.mail.genotec.ch   internet address = 217.26.49.141
mx1.mail.genotec.ch   internet address = 217.26.49.140
mx2.mail.genotec.ch   internet address = 217.26.49.139
mx1.mail.genotec.ch   internet address = 217.26.49.142
>

nslookup.exe help

Commands:   (identifiers are shown in uppercase, [] means optional)
NAME            - print info about the host/domain NAME using default server
NAME1 NAME2     - as above, but use NAME2 as server
help or ?       - print info on common commands
set OPTION      - set an option
    all                 - print options, current server and host
    [no]debug           - print debugging information
    [no]d2              - print exhaustive debugging information
    [no]defname         - append domain name to each query
    [no]recurse         - ask for recursive answer to query
    [no]search          - use domain search list
    [no]vc              - always use a virtual circuit
    domain=NAME         - set default domain name to NAME
    srchlist=N1[/N2/.../N6] - set domain to N1 and search list to N1,N2, etc.
    root=NAME           - set root server to NAME
    retry=X             - set number of retries to X
    timeout=X           - set initial time-out interval to X seconds
    type=X              - set query type (ex. A,AAAA,A+AAAA,ANY,CNAME,MX,NS,PTR,SOA,SRV)
    querytype=X         - same as type
    class=X             - set query class (ex. IN (Internet), ANY)
    [no]msxfr           - use MS fast zone transfer
    ixfrver=X           - current version to use in IXFR transfer request
server NAME     - set default server to NAME, using current default server
lserver NAME    - set default server to NAME, using initial server
root            - set current default server to the root
ls [opt] DOMAIN [> FILE] - list addresses in DOMAIN (optional: output to FILE)
    -a          -  list canonical names and aliases
    -d          -  list all records
    -t TYPE     -  list records of the given RFC record type (ex. A,CNAME,MX,NS,PTR etc.)
view FILE           - sort an 'ls' output file and view it with pg
exit            - exit the program

Install HP Support Pack on Hyper-V R2 Core Server

If you are using Microsoft Hyper-V R2 Core Server, installing the HP Support Pack is a little different. This post should show you how this is done.

  1. Download the latest HP Support Pack for Windows Server 2008 R2 and extract that on your Management Server or PC.
  2. Now copy the extracted folder to the Hyper-V Core Server. In my case i copied in the C:\ root of the Core Server via the administrative network share. If you have easy physical access to the server, you could also use a USB stick or something like that.
    Copy HP Support Pack to Core Server
  3. Now connect to the Core Server and use the cmd.exe to navigate to the folder with the HP Support Pack
    Hyper-V Core Server HP Support Pack
  4. Run the “hpsum.exe” to start the HP Smart Update Manager
    hpsum.exe
  5. When the HP Smart Update Manager is started you can use it like on a Full Server installation of Windows Server 2008
    HP Smart Update Manager on Hyper-V Core ServerHP Smart Update Manager on Hyper-V Core ServerHP Smart Update Manager on Hyper-V Core Server

You could also try to run the HP Smart Update Manager on another machine and use the remote connection feature.

Powershell iTunes v1

Powershell iTunesIn the last days I worked with Powershell and ComObjects. It turned out that iTunes is a really good exmaple for using ComObjects with Powershell, thats why I wrote this little Script.
Powershell iTunes is a Powershell script which lets you control iTunes over Powershell.

Howto:

  1. Download Powershellitunes.zip
  2. Extract the Files where ever you wanna save the powershell script
  3. Run the script
    Powershell iTunes
  4. Now you can run the Powershell Cmdlets

Powershell iTunes Commands:

  • Start-iTunes
  • Close-iTunes
  • Play-Track
  • Pause-Track
  • Resume-Track
  • Back-Track
  • Next-Track
  • Mute-Track
  • Unmute-Track
  • Show-iTunesVersion
  • Set-VolumeDown
  • Set-VolumeUp
  • Set-Volume

The Script:

#
#*****************************************************************
#
# Powershell iTunes v1 $Rev: 754 $
# (c) 2004-2010 Thomas Maurer. All rights reserved.
# created by Thomas Maurer
#
# http://www.thomasmaurer.ch
# http://www.thomasmaurer.ch/projects
#
# last Update by $Author: tmaurer $ on $Date: 2010-11-24 07:50:06 +0100 (Mi, 24 Nov 2010) $
#
# Version 1.0.1
#
#*****************************************************************
#

# Welcome
Write-Host "                                                                  " -BackgroundColor Black -ForegroundColor White
Write-Host "    ____                               __         ____            " -BackgroundColor Black -ForegroundColor White
Write-Host "   / __ \____ _      _____  __________/ /_  ___  / / /            " -BackgroundColor Black -ForegroundColor White
Write-Host "  / /_/ / __ \ | /| / / _ \/ ___/ ___/ __ \/ _ \/ / /             " -BackgroundColor Black -ForegroundColor White
Write-Host " / ____/ /_/ / |/ |/ /  __/ /  (__  ) / / /  __/ / /              " -BackgroundColor Black -ForegroundColor White
Write-Host "/_/    \____/|__/|__/\___/_/  /____/_/ /_/\___/_/_/               " -BackgroundColor Black -ForegroundColor White
Write-Host "                                                                  " -BackgroundColor Black -ForegroundColor White
Write-Host "    _ ______                                                      " -BackgroundColor Black -ForegroundColor White
Write-Host "   (_)_  __/_  ______  ___  _____                                 " -BackgroundColor Black -ForegroundColor White
Write-Host "  / / / / / / / / __ \/ _ \/ ___/                                 " -BackgroundColor Black -ForegroundColor White
Write-Host " / / / / / /_/ / / / /  __(__  )                                  " -BackgroundColor Black -ForegroundColor White
Write-Host "/_/ /_/  \__,_/_/ /_/\___/____/                                   " -BackgroundColor Black -ForegroundColor White
Write-Host "                                                                  " -BackgroundColor Black -ForegroundColor White
Write-Host "******************************************************************" -BackgroundColor Black -ForegroundColor White
Write-Host "                                                                  " -BackgroundColor Black -ForegroundColor White
Write-Host " Welcome to the Powershell iTunes                                 " -BackgroundColor Black -ForegroundColor White
Write-Host "                                                                  " -BackgroundColor Black -ForegroundColor White
Write-Host " (c) 2010 Thomas Maurer www.thomasmaurer.ch/projects              " -BackgroundColor Black -ForegroundColor White
Write-Host "                                                                  " -BackgroundColor Black -ForegroundColor White
Write-Host "******************************************************************" -BackgroundColor Black -ForegroundColor White
Write-Host "                                                                  " -BackgroundColor Black -ForegroundColor White
Write-Host " for Help use the Get-PSiTunesHelp                                " -BackgroundColor Black -ForegroundColor White
Write-Host "                                                                  " -BackgroundColor Black -ForegroundColor White

# Add ComObjects to $iTunes
$iTunes = New-Object -ComObject iTunes.Application

# Function to start itunes
function Start-iTunes {
    process {

		$iTunesRunning = Get-Process | Where-Object {$_.ProcessName -eq "iTunes"}
		if(!$iTunesRunning) {
			$script:iTunes = New-Object -ComObject iTunes.Application
			Write-Host "(PS iTunes): iTunes started" -BackgroundColor Black -ForegroundColor green
		}
		else {
			Write-Host "(PS iTunes): iTunes allready running" -BackgroundColor Black -ForegroundColor red
		}
	}
}

# Function to close itunes
function Close-iTunes {
    process {

		$iTunesRunning = Get-Process | Where-Object {$_.ProcessName -eq "iTunes"}
		if(!$iTunesRunning) {
			Write-Host "(PS iTunes): iTunes not running" -BackgroundColor Black -ForegroundColor red
		}
		else {
			Stop-Process $iTunesRunning.Id
			Write-Host "(PS iTunes): iTunes closed" -BackgroundColor Black -ForegroundColor red
		}
	}
}

# Function to play a song
function Play-Track {
    process {
		if ($iTunes.Playerstate -eq "0"){
			$iTunes.Play()
			Write-Host "(PS iTunes): Now playing:" $iTunes.CurrentTrack.Name "from" $iTunes.CurrentTrack.Artist -BackgroundColor Black -ForegroundColor green
		}
		else {
			Write-Host "(PS iTunes): Already playing Track:" $iTunes.CurrentTrack.Name "from" $iTunes.CurrentTrack.Artist -BackgroundColor Black -ForegroundColor red
		}
	}
}

# Function to stop a song
function Pause-Track {
    process {
        if ($iTunes.Playerstate -eq "1"){
			$iTunes.Pause()
			Write-Host "(PS iTunes): iTunes paused" -BackgroundColor Black -ForegroundColor Red
		}
		else {
			Write-Host "(PS iTunes): Not playing any track" -BackgroundColor Black -ForegroundColor red
		}
	}
}

# Function to resume a song
function Resume-Track {
    process {
    	if ($iTunes.Playerstate -eq "0"){
			$iTunes.Play()
			Write-Host "(PS iTunes): Now playing:" $iTunes.CurrentTrack.Name "from" $iTunes.CurrentTrack.Artist -BackgroundColor Black -ForegroundColor green
		}
		else {
			Write-Host "(PS iTunes): Already playing Track:" $iTunes.CurrentTrack.Name "from" $iTunes.CurrentTrack.Artist -BackgroundColor Black -ForegroundColor red
		}
	}
}

# Function to go a song back
function Back-Track {
    process {
	$iTunes.BackTrack()
	Write-Host "(PS iTunes): Now playing:" $iTunes.CurrentTrack.Name "from" $iTunes.CurrentTrack.Artist -BackgroundColor Black -ForegroundColor green
	}
}

# Function to go to the next
function Next-Track {
    process {
	$iTunes.NextTrack()
	Write-Host "(PS iTunes): Now playing:" $iTunes.CurrentTrack.Name "from" $iTunes.CurrentTrack.Artist -BackgroundColor Black -ForegroundColor green
	}
}

# Function to get infos about the current track
function Get-CurrentTrack {
    process {
	Write-Host "(PS iTunes): Currently playing:" $iTunes.CurrentTrack.Name "from" $iTunes.CurrentTrack.Artist -BackgroundColor Black -ForegroundColor White
	}
}

# Function to mute itunes
function Mute-iTunes {
    process {
        if($itunes.Mute -eq $false) {
			$itunes.Mute = $true
			Write-Host "(PS iTunes): iTunes muted" -BackgroundColor Black -ForegroundColor Red
		}
		else {
			Write-Host "(PS iTunes): iTunes already muted" -BackgroundColor Black -ForegroundColor red
		}
	}
}

# Function to unmute itunes
function Unmute-iTunes {
    process {
    	if($itunes.Mute -eq $true) {
			$itunes.Mute = $false
			Write-Host "(PS iTunes): iTunes unmuted" -BackgroundColor Black -ForegroundColor green
		}
		else {
			Write-Host "(PS iTunes): iTunes already unmuted" -BackgroundColor Black -ForegroundColor red
		}
	}
}

# Function to set iTunes volume up
function Set-VolumeUP {
    process {
		if($iTunes.SoundVolume -lt 100) {
			$iTunes.SoundVolume = $iTunes.SoundVolume + 2
			Write-Host "(PS iTunes): iTunes Volume" $iTunes.SoundVolume -BackgroundColor Black -ForegroundColor green
		}
		else {
			Write-Host "(PS iTunes): iTunes Volume is already 100%" -BackgroundColor Black -ForegroundColor red
		}
	}
}

# Function to set iTunes volume down
function Set-VolumeDown {
    process {
		if($iTunes.SoundVolume -gt 0) {
			$iTunes.SoundVolume = $iTunes.SoundVolume - 2
			Write-Host "(PS iTunes): iTunes Volume" $iTunes.SoundVolume -BackgroundColor Black -ForegroundColor red
		}
		else {
			Write-Host "(PS iTunes): iTunes Volume is already 0%" -BackgroundColor Black -ForegroundColor red
		}
	}
}

# Function to set iTunes
function Set-Volume {
	param (
		[int]$Volume
	)
    process {
		if($Volume -ge 0 -and $Volume -le 100) {
			$iTunes.SoundVolume = $Volume
			Write-Host "(PS iTunes): iTunes Volume" $iTunes.SoundVolume -BackgroundColor Black -ForegroundColor green
		}
		else {
			Write-Host "(PS iTunes): Volume has to be 0-100" -BackgroundColor Black -ForegroundColor red
		}
	}
}

# Function to show the Version of iTunes
function Show-iTunesVersion {
    process {
	Write-Host "(PS iTunes): iTunes Version" $iTunes.version -BackgroundColor Black -ForegroundColor White
	}
}

# Function to show the Version of iTunes
function get-PSiTunesHelp {
    process {
	Write-Host " "
	Write-Host " Powershell iTunes Help"
	Write-Host " "
	Write-Host "********************************************************"
	Write-Host " "
	Write-Host " Commands"
	Write-Host " "
	Write-Host " Start-iTunes			Starts iTunes"
	Write-Host " Close-iTunes			Closes iTunes"
	Write-Host " Play-Track			Plays a iTunes Track"
	Write-Host " Pause-Track			Pauses a iTunes Track"
	Write-Host " Resume-Track			Resumes a iTunes Track"
	Write-Host " Back-Track			Go to the last iTunes Track"
	Write-Host " Next-Track			Plays next iTunes Track"
	Write-Host " Mute-Track			Mutes iTunes"
	Write-Host " Unmute-Track			Unmutes iTunes"
	Write-Host " Show-iTunesVersion		Shows iTunes Version"
	Write-Host " Set-VolumeDown			Set Volume Down"
	Write-Host " Set-VolumeUp			Set Volume Up"
	Write-Host " Set-Volume			Set iTunes Volume (0-100)"
	}
}

I released this here: http://www.thomasmaurer.ch/projects/powershell-itunes/

Cheatsheet: Using Diskpart on a Server Core installation #4

Using Diskpart on a Server Core installation. Disk Administration or Partition a disk.

Create a new partition and format a partition

SELECT DISK 0
CREATE PARTITION PRIMARY
ASSIGN LETTER=E
SELECT PARTITION 1
FORMAT FS=NTFS LABEL="New Volume" QUICK
EXIT

Commands you may then issue at the DISKPART prompt:

LIST Disk
LIST Partition
LIST Volume

SELECT Disk n
SELECT Volume n
SELECT Partition n

DETAIL Disk
DETAIL Partition
DETAIL volume

HELP
REM (remark/comment)
EXIT

Commands to Manage Basic Disks:

(set the current in-focus partition to be the system partition)

ASSIGN (allocate the next free drive letter)
ASSIGN LETTER=l (Choose a free letter)

CREATE PARTITION Primary Size=50000 (50 GB)
CREATE PARTITION Extended Size=25000
CREATE PARTITION logical Size=25000

DELETE Partition

EXTEND Size=10000

REMOVE letter=l (Remove drive letter l from the in-focus partition)
REMOVE /ALL (Remove ALL current drive letters and mount points)

Commands to Manage Dynamic Disks:

(set the current in-focus partition to be the system partition)

ASSIGN (allocate the next free drive letter)
ASSIGN LETTER=l (Choose a free letter)

ADD disk=n (Add a mirror to the in-focus SIMPLE volume on the specified disk.)

BREAK disk=n (Break the current in-focus mirror)

CREATE VOLUME Simple Size=n Disk=n
CREATE VOLUME Stripe Size=n Disk=n,n,...
CREATE VOLUME Raid Size=n Disk=n,n,...

DELETE DISK
DELETE PARTITION
DELETE VOLUME

EXTEND disk=n [Size=n]
IMPORT
ONLINE

REMOVE letter=l (Remove drive letter l from the in-focus volume)
REMOVE /ALL (Remove ALL current drive letters and mount points)
RETAIN

Commands to Convert Disks:

CONVERT mbr
CONVERT gpt
CONVERT dynamic
CONVERT basic

CLEAN ALL (remove all partition and volume info from the hard drive)
RESCAN