Windows Server 2008 R2 Default Background Color

For a documentation I changed the background color of my Windows Server 2008 R2 to
white. After I finished my documentation I wanted to change the colors back to
the default Windows Server Background Color. I realized that this was not a
default Color to choose. But you can set the color by enter the RGB values.

backgroundThe RGB values for Windows Server 2008 R2 Desktop are:

Red = 58
Green = 110
Blue = 165

Powershell: Run MySQL Querys with Powershell

Powershell Header
In our Hosting enviroment we are now using MS SQL Servers for our back-end. But there are still some MySQL Server left which store some data. Now since we do a lot of automation with Windows Powersehll I wrote a function to run MySQL querys with Powershell.

First you have to install the MySQL .NET Connector or just copy the MySql.Data.dll from the MySQL.

You can now load this:

With DLL File:

 [void][system.reflection.Assembly]::LoadFrom("C:\myscript\MySQL.Data.dll")

or if you have installed the MySQL .NET Connector:

 [void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data") 

Now basiclly this function does everything for you:

Function Run-MySQLQuery {
<#
.SYNOPSIS
   run-MySQLQuery

.DESCRIPTION
   By default, this script will:
    - Will open a MySQL Connection
	- Will Send a Command to a MySQL Server
	- Will close the MySQL Connection
	This function uses the MySQL .NET Connector or MySQL.Data.dll file

.PARAMETER ConnectionString
    Adds the MySQL Connection String for the specific MySQL Server

.PARAMETER Query

    The MySQL Query which should be send to the MySQL Server

.EXAMPLE
    C:\PS> run-MySQLQuery -ConnectionString "Server=localhost;Uid=root;Pwd=p@ssword;database=project;" -Query "SELECT * FROM firsttest" 

    Description
    -----------
    This command run the MySQL Query "SELECT * FROM firsttest"
	to the MySQL Server "localhost" with the Credentials User: Root and password: p@ssword and selects the database project

.EXAMPLE
    C:\PS> run-MySQLQuery -ConnectionString "Server=localhost;Uid=root;Pwd=p@ssword;database=project;" -Query "UPDATE firsttest SET firstname='Thomas' WHERE Firstname like 'PAUL'" 

    Description
    -----------
    This command run the MySQL Query "UPDATE project.firsttest SET firstname='Thomas' WHERE Firstname like 'PAUL'"
	to the MySQL Server "localhost" with the Credentials User: Root and password: p@ssword

.EXAMPLE
    C:\PS> run-MySQLQuery -ConnectionString "Server=localhost;Uid=root;Pwd=p@ssword;" -Query "UPDATE project.firsttest SET firstname='Thomas' WHERE Firstname like 'PAUL'" 

    Description
    -----------
    This command run the MySQL Query "UPDATE project.firsttest SET firstname='Thomas' WHERE Firstname like 'PAUL'"
	to the MySQL Server "localhost" with the Credentials User: Root and password: p@ssword and selects the database project

#>
	Param(
        [Parameter(
            Mandatory = $true,
            ParameterSetName = '',
            ValueFromPipeline = $true)]
            [string]$query,
		[Parameter(
            Mandatory = $true,
            ParameterSetName = '',
            ValueFromPipeline = $true)]
            [string]$connectionString
        )
	Begin {
		Write-Verbose "Starting Begin Section"
    }
	Process {
		Write-Verbose "Starting Process Section"
		try {
			# load MySQL driver and create connection
			Write-Verbose "Create Database Connection"
			# You could also could use a direct Link to the DLL File
			# $mySQLDataDLL = "C:\scripts\mysql\MySQL.Data.dll"
			# [void][system.reflection.Assembly]::LoadFrom($mySQLDataDLL)
			[void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data")
			$connection = New-Object MySql.Data.MySqlClient.MySqlConnection
			$connection.ConnectionString = $ConnectionString
			Write-Verbose "Open Database Connection"
			$connection.Open()

			# Run MySQL Querys
			Write-Verbose "Run MySQL Querys"
			$command = New-Object MySql.Data.MySqlClient.MySqlCommand($query, $connection)
			$dataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($command)
			$dataSet = New-Object System.Data.DataSet
			$recordCount = $dataAdapter.Fill($dataSet, "data")
			$dataSet.Tables["data"] | Format-Table
		}
		catch {
			Write-Host "Could not run MySQL Query" $Error[0]
		}
		Finally {
			Write-Verbose "Close Connection"
			$connection.Close()
		}
    }
	End {
		Write-Verbose "Starting End Section"
	}
}

You can use this Powershell function like this:

run-MySQLQuery -ConnectionString "Server=localhost;Uid=root;Pwd=p@ssword;database=project;" -Query "SELECT * FROM firsttest"

If you wanna run more than one command you could do something like this:

$connString = "Server=localhost;Uid=root;Pwd=p@ssword;database=project;"

[array]$sQLDings += "SELECT * from project.firsttest"
[array]$sQLDings += "UPDATE project.firsttest SET firstname='Thomas' WHERE Firstname like 'Paul'"
[array]$sQLDings += "SELECT * from project.firsttest"

foreach($sQLquery in $SQLDings) {
	run-MySQLQuery -connectionString $connString -query $sQLquery
}

If you need more information about Powershell and MySQL Mark Alexander Bain wrote a blog post about this.

And if you need a local MySQL Server on your machine to test this, you could use Microsoft Platform Installer to install MySQL and other cool Webtools.

Windows Server 2008 R2 Hyper-V Licensing Overview

hyper-v

This is a little Overview how you can license Windows Server 2008 R2 in a Hyper-V Environment. One of the biggest advantages  of Hyper-V over VMware are the included Guest OS Licenses. For example if you buy a Windows Server 2008 R2 Datacenter license (of each CPU of your physical Server) you can deploy unlimited Windows Server 2008 R2 Datacenter Virtual Machines on this Host.

This Overview should help you understand how this works.

License License models Physical Virtual
Windows Server 2008 R2 Foundation Server License 1 0
Windows Server 2008 R2 Standard Server + CAL
Processor or SAL
1 1
Windows Server 2008 R2 Enterprise Server + CAL
Processor or SAL
1 4
Windows Server 2008 R2 Datacenter Processor + CAL 1 unlimited
Windows Server 2008 R2 for Itanium-Based Systems Processor + CAL 1 unlimited
Windows Web Server 2008 R2 Server License 1 0 (or 1)
Hyper-V Server 2008 R2 Free 1 0

 

If you need more infos you can find this here.

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

Quick Powershell Remoting Guide

Powershell HeaderThis is small guide which allows you to create Remote Powershell Sessions (like SSH). It allows you to create connection to Host which have Powershell Version 2.

  • Allow Powershell Remoting on the Remotehost
  • Add Trusted Hosts on the Localcomputer
  • Create a new Remotesession
  • Leave a Powershell Remotesession
  • Close a Powershell Remotesession
  • Send a command to a Remotehost

Allow Powershell Remoting on the Remotehost

Run Powershell 2.0 on the Remotehost and run the following Cmdlet.

Enable-PSRemoting

This command starts the WinRM service if it’s not allready started and sets the startup type to automatic. Adds firewall exceptions for WS-Management communications and creates a listener to accept requests.

Add Trusted Hosts on the Localcomputer

On the Local Computer run Powershell and run the following Cmdlet. This allows you to connect to any host. It also starts WinRM if its not already started.

Set-Item WSMan:\localhost\Client\TrustedHosts *

After that you may have to restart the WinRM service

Restart-Service winrm -Force

Create a new Powershell Remotesession

There are two ways to create a new PS Remotesession.

New-PSSession -ComputerName Server01

With Get-PSSession you can list all active sessions. Now you can enter a active Session with Enter-PSSession and the ID

Enter-PSSession 2

A quicker way to do that, you can simply use Enter-PSSession to create a new Session and directly connect to this Session.

Enter-PSSession -ComputerName Server02

Leave a Powershell Remotesession

To leave a Powershell Remotesession you can simply use the Exit-PSSession

Exit-PSSession

Close a Powershell Remotesession

To close a Powershell Remotesession you can list all  active Sessions with Get-PSSessions and close them with Remove-PSSession.

Get-PSSession | Remove-PSSession

Send a command to a Remotehost

To run a command on a Remotehost you can use the -ComputerName parameter.

Get-Service -ComputerName Server02
Get-Service -ComputerName Server02 | Where-Object {$_.Name -eq "BITS"}

With this little snippet you can run commands on multiple Hosts


$Servers = @("Server01", "Server02")

foreach ($Server in $Servers) {

Write-Host "Server: " $server

Get-Service -ComputerName $server | Where-Object {$_.Name -eq "BITS"}

}

Remote Disk Management with “RPC server is unavailable” Error

If you have a Windows Server 2008 R2 Core Server or a Hyper-V R2 Server, which is also managed like a Core Server, you are really happy if you can use the Server Manager for this Remote Machine. Basiclly I had the the Remote Setup done. I could connect to the remote Machine with the Server Manager but when I tried to use the Disk Management on a remote Server and I got the following error “RPC server is unavailable”. After checking it I found the solution. The Problem is that the Firewall blocks the remote communication to virtual disk service. So you have to open the Firewall on the Management Machine

  1. First make sure you activated all the Remote Management options on the Remote Machine. I had all done this but its good to check that.
  2. Now you can run the following Command in cmd on the Management Machine to add the a new firewall rule
    netsh advfirewall firewall set rule group="Remote Volume Management" new enable=yes

firewall