<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Thomas Maurer (tm) &#187; PowerShell</title>
	<atom:link href="http://www.thomasmaurer.ch/tag/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thomasmaurer.ch</link>
	<description>Just another private cloud weblog</description>
	<lastBuildDate>Mon, 06 Feb 2012 19:10:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Hyper-V 3: Import and Export VMs with PowerShell</title>
		<link>http://www.thomasmaurer.ch/2011/12/hyper-v-3-import-and-export-vms-with-powershell/</link>
		<comments>http://www.thomasmaurer.ch/2011/12/hyper-v-3-import-and-export-vms-with-powershell/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 21:01:29 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[Hyper-V]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Windows Server 8]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Export-VM]]></category>
		<category><![CDATA[Hyper-V 3]]></category>
		<category><![CDATA[Import-VM]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Powershell 3]]></category>
		<category><![CDATA[Virtual machines]]></category>
		<category><![CDATA[VM]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=3032</guid>
		<description><![CDATA[Aidan Finn (Virtual Machine MVP) just made a blog post about Hyper-V &#38; PowerShell in Windows Server 8 and how you can enable Hyper-V via PowerShell in Windows Server 8. So this gave me the idea about doing a little &#8230; <a href="http://www.thomasmaurer.ch/2011/12/hyper-v-3-import-and-export-vms-with-powershell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='small' href='http://www.thomasmaurer.ch/2011/12/hyper-v-3-import-and-export-vms-with-powershell/'></g:plusone></div><div class='dd_button'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.thomasmaurer.ch/2011/12/hyper-v-3-import-and-export-vms-with-powershell/" data-count="horizontal" data-text="Hyper-V 3: Import and Export VMs with PowerShell" data-via="thomasmaurer" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class='dd_button'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.thomasmaurer.ch%2F2011%2F12%2Fhyper-v-3-import-and-export-vms-with-powershell%2F&amp;locale=en_US&amp;layout=button_count&amp;action=like&amp;width=92&amp;height=20&amp;colorscheme=light' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:92px; height:20px;' allowTransparency='true'></iframe></div></div><div style='clear:both'></div></div><div style='clear:both'></div><p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2011/12/Hyper-V-Powershell02.png" rel="lightbox[3032]"><img class="aligncenter size-medium wp-image-3037" title="Hyper-V-Powershell02" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/12/Hyper-V-Powershell02-300x149.png" alt="Hyper-V-Powershell02" width="300" height="149" /></a></p>
<p>Aidan Finn (Virtual Machine MVP) just made a <a href="http://www.aidanfinn.com/?p=11941" target="_blank">blog post</a> about Hyper-V &amp; PowerShell in Windows Server 8 and how you can enable Hyper-V via PowerShell in Windows Server 8. So this gave me the idea about doing a little more with PowerShell and Hyper-V 3.</p>
<p>I already did a<a href="http://www.thomasmaurer.ch/2011/09/hyper-v-3-attach-multiple-vhds-via-powershell/" target="_blank"> blog post about how you can attach multiple VHDs </a>to a SCSI Controller with PowerShell in Windows Server 8. In this post I will show how easy you can export and import a lot of Virtual Machines.</p>
<p>First you can run a Get-VM Test*, to check which VMs you will export.</p>
<pre>

Get-VM Test*
</pre>
<p>Now you can export the Virtual Machines</p>
<pre>

Get-VM Test* | Export-VM -Path "C:\VMs"
</pre>
<p>Now I removed the Virtual Machines in Hyper-V with Powershell (You could also add the -confirm parameter so you don&#8217;t have to press &#8220;y&#8221; for each VM.</p>
<pre>

Get-VM Test* | Remove-VM
</pre>
<p>And now you can import the Virtual Machines again</p>
<pre>

Get-Childitem "C:\VMs" -Recurse *.xml | Import-VM
</pre>
<p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2011/12/Hyper-V-Powershell01.png" rel="lightbox[3032]"><img class="aligncenter size-medium wp-image-3035" title="Hyper-V-Powershell01" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/12/Hyper-V-Powershell01-300x223.png" alt="Hyper-V-Powershell01" width="300" height="223" /></a></p>
<p>I will post more about PowerShell in Windows 8 and Windows Server 8 (Hyper-V 3) in the next upcommig weeks. If you want know more about what new Hyper-V features and improvments are coming in Windows Server 8, you can read the following blog post: &#8220;<a title="Hyper-V: “Version 3 kills them all”" href="http://www.thomasmaurer.ch/2011/09/hyper-v-version-3-kills-them-all/" target="_blank">Hyper-V: Version 3 kills them all</a>&#8221;</p>
<p>&nbsp;</p>
<!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com --><div class="shr-publisher-3032"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2011/12/hyper-v-3-import-and-export-vms-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automated Active Directory Deployment with PowerShell</title>
		<link>http://www.thomasmaurer.ch/2011/12/automated-active-directory-deployment-with-powershell/</link>
		<comments>http://www.thomasmaurer.ch/2011/12/automated-active-directory-deployment-with-powershell/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 19:06:08 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Windows Server 2008 R2]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Config]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[Dcpromo]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Remoting]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=3024</guid>
		<description><![CDATA[For a small presentation at KTSI I created a PowerShell script will automatically will deploys Active Directory Servers, adds other member servers, creates Organization Units and adds users via Powershell Remoting. As source there is a XML configuration file and &#8230; <a href="http://www.thomasmaurer.ch/2011/12/automated-active-directory-deployment-with-powershell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='small' href='http://www.thomasmaurer.ch/2011/12/automated-active-directory-deployment-with-powershell/'></g:plusone></div><div class='dd_button'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.thomasmaurer.ch/2011/12/automated-active-directory-deployment-with-powershell/" data-count="horizontal" data-text="Automated Active Directory Deployment with PowerShell" data-via="thomasmaurer" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class='dd_button'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.thomasmaurer.ch%2F2011%2F12%2Fautomated-active-directory-deployment-with-powershell%2F&amp;locale=en_US&amp;layout=button_count&amp;action=like&amp;width=92&amp;height=20&amp;colorscheme=light' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:92px; height:20px;' allowTransparency='true'></iframe></div></div><div style='clear:both'></div></div><div style='clear:both'></div><p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/powershell1.png" rel="lightbox[3024]"><img class="aligncenter size-medium wp-image-2607" title="Powershell" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/powershell1-300x95.png" alt="Powershell" width="300" height="95" /></a></p>
<p>For a small presentation at <a title="ktsi" href="http://www.ktsi.ch" target="_blank">KTSI</a> I created a PowerShell script will automatically will deploys Active Directory Servers, adds other member servers, creates Organization Units and adds users via Powershell Remoting. As source there is a XML configuration file and CSV files for User Data.</p>
<p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2011/12/Drawing1.jpg" rel="lightbox[3024]"><img class="aligncenter size-medium wp-image-3025" title="Install AD with Powershell" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/12/Drawing1-243x300.jpg" alt="Install AD with Powershell" width="243" height="300" /></a></p>
<p>This script is just for Lab deployments not for production, and it is not perfect, but I think maybe some people will enhance this script with their own code.</p>
<p>I do not support this script. it is just something I need to deploy my test environments and nothing more. More it shows diffrent</p>
<p>You can find more information about it works in this <a title="document" href="https://skydrive.live.com/redir.aspx?cid=7298a00d5b74ec3c&amp;resid=7298A00D5B74EC3C!762&amp;parid=7298A00D5B74EC3C!731&amp;authkey=!ALRYJJ5cunSPo3M" target="_blank">document</a>.</p>
<p>XML Config file:</p>
<pre>

&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;lab&gt;
&lt;config&gt;
&lt;servers&gt;
&lt;server name="ADS01" ip="192.168.100.11" id="1" adminpw="passw0rd"/&gt;
&lt;server name="ADS02" ip="192.168.100.12" id="2" adminpw="passw0rd"/&gt;
&lt;/servers&gt;
&lt;ad&gt;
&lt;domain name="ktsi.local" netbiosname="ktsi" forestlevel="4" domainlevel="4" safemodepw="passw0rd" /&gt;
&lt;/ad&gt;
&lt;ous&gt;
&lt;ou name="UserAccounts" path="DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="BASEL" path="OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="CHICAGO" path="OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="NEWYORK" path="OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="SALES" path="OU=BASEL,OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="IT" path="OU=BASEL,OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="ADMINISTRATION" path="OU=BASEL,OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="PRODUCTION" path="OU=BASEL,OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="SALES" path="OU=CHICAGO,OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="IT" path="OU=CHICAGO,OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="ADMINISTRATION" path="OU=CHICAGO,OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="PRODUCTION" path="OU=CHICAGO,OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="SALES" path="OU=NEWYORK,OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="IT" path="OU=NEWYORK,OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="ADMINISTRATION" path="OU=NEWYORK,OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;ou name="PRODUCTION" path="OU=NEWYORK,OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;/ous&gt;
&lt;users&gt;
&lt;file name="users.csv" path="OU=ADMINISTRATION,OU=BASEL,OU=USERACCOUNTS,DC=KTSI,DC=LOCAL" /&gt;
&lt;/users&gt;
&lt;members&gt;
&lt;member name="PC101" ip="192.168.100.21" /&gt;
&lt;member name="PC101" ip="192.168.100.22" /&gt;
&lt;member name="PC101" ip="192.168.100.23" /&gt;
&lt;/members&gt;
&lt;/config&gt;
&lt;/lab&gt;
</pre>
<p>The PowerShell Script:</p>
<p><span id="more-3024"></span></p>
<pre>

&nbsp;

# ---------------------------------------------------------------------------------------------- #

# Powershell AD Creator $Rev: 748 $

# (c) 2011 Thomas Maurer. All rights reserved.

# created by Thomas Maurer

# last Update by $Author: tmaurer $ on $Date: 2010-11-22 14:07:36 +0100 (Mo, 04 Nov 2011) $

# ---------------------------------------------------------------------------------------------- #

&nbsp;

&nbsp;

# Set Debug Mode (true/false)

$DebugOn = $false

&nbsp;

&nbsp;

&nbsp;

#region [INFO BLOCK]

# INFO

Write-Host " " -BackgroundColor Black -ForegroundColor White

Write-Host "PowerShell AD Deplyoment" -BackgroundColor Black -ForegroundColor White

Write-Host " " -BackgroundColor Black -ForegroundColor White

Write-Host "Enter Credentials for Remote System:" -BackgroundColor Black -ForegroundColor White

#endregion

&nbsp;

&nbsp;

#region [VERBOSE BLOCK]

# Verbose Loop

&nbsp;

if ($DebugOn -eq $true){

#Debug

Clear-Host

Write-Host "Debug mode on" -BackgroundColor Red -ForegroundColor White

$VerbosePreference = "Continue"

}

else {

#NoDebug

Clear-Host

$VerbosePreference = "SilentlyContinue"

}

#endregion

&nbsp;

#region [CONFIG BLOCK]

# Get XML Information and create some funny objects...

[Xml]$global:xmlData = get-content ".\config.xml"

&nbsp;

# Get Credentials for Remotesystems

$cred = Get-Credential

&nbsp;

$global:xmlServer01 = $xmlData.lab.config.servers.server | Where-Object { $_.id -eq "1"}

$global:xmlServer02 = $xmlData.lab.config.servers.server | Where-Object { $_.id -eq "2"}

$global:xmlDomain = $xmlData.lab.config.ad.domain

$global:xmlOUS = $xmlData.lab.config.ous

&nbsp;

#endregion

&nbsp;

#region [FUNCTION BLOCK]

&nbsp;

function ConvertTo-Scriptblock {

&lt;#

Function to Convert a String into a Script Block

#&gt;

Param(

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$string

)

Begin {

Write-Verbose "Starting Begin Section"

}

Process {

Write-Verbose "Starting Process Section"

try {

Write-Verbose "Convert String to Scriptblock"

$sb = [scriptblock]::Create($string)

return $sb

}

catch {

Write-Host "Could not convert String to Scriptblock" $Error[0]

&nbsp;

}

}

End {

Write-Verbose "Starting End Section"

}

}

&nbsp;

&nbsp;

function Enable-ICMP {

&lt;#

Function to enable ICMP

&nbsp;

Enable-ICMP -hostip $xmlServer01.ip

#&gt;

Param(

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$hostip

)

begin {

# Write Command

$step001 = @"

netsh firewall set icmpsetting 8

"@

}

process {

try {

# Run Scriptblock

Write-Host "Enable ICMP on " $hostip "..." -BackgroundColor Black -ForegroundColor White

&nbsp;

Invoke-Command -ComputerName $hostip -ScriptBlock (ConvertTo-Scriptblock -String $step001) -Credential $cred

Write-Host "ICMP successfully enabled..." -BackgroundColor Green -ForegroundColor Black

&nbsp;

&nbsp;

}

catch {

# Sending status to CP and EventLog

throw "ERROR: Could not enable ICMP"

}

}

end {

# Cleanup

$step001 = $null

}

}

&nbsp;

&nbsp;

&nbsp;

function Create-ADServer {

&lt;#

Function to Create AD on the first Server

#&gt;

begin {

# Prepair for First AD Server

Write-Host "Preparing Script Block for " + $xmlServer01.name + "..." -BackgroundColor Black -ForegroundColor White

$domainName = $xmldomain.name

$domainNetBiosName = $xmldomain.netbiosname

$domainForestLevel = $xmldomain.forestlevel

$domainDomainLevel = $xmldomain.domainlevel

$domainSafemodePW = $xmldomain.safemodepw

$adTempFolder = "temp4"

$adTempPath = "C:\" + $adTempFolder

$adFilePath = $adTempPath + "\adinstall.txt"

}

process {

try {

# Script Block for First AD Server

$step001 = @"

New-Item -ItemType directory $adTempPath

New-Item -ItemType file $adFilePath

Add-Content $adFilePath "[DCINSTALL]"

Add-Content $adFilePath "InstallDNS=yes"

Add-Content $adFilePath "NewDomain=forest"

Add-Content $adFilePath "NewDomainDNSName=$domainName"

Add-Content $adFilePath "DomainNetBiosName=$domainNetBiosName"

Add-Content $adFilePath "ReplicaOrNewDomain=domain"

Add-Content $adFilePath "ForestLevel=$domainForestLevel"

Add-Content $adFilePath "DomainLevel=$domainDomainLevel"

Add-Content $adFilePath "RebootOnCompletion=yes"

Add-Content $adFilePath "SafeModeAdminPassword=$domainSafemodePW"

Write-Host "Unattend File created successfully..." - -BackgroundColor Green

dcpromo /unattend:$adFilePath

"@

# Run Scriptblock

Write-Host "Configure " $xmlServer01 "..." -BackgroundColor Black -ForegroundColor White

Invoke-Command -ComputerName $xmlServer01.ip -ScriptBlock (ConvertTo-Scriptblock -String $step001) -Credential $cred

Write-Host "Configuration for " $xmlServer01.name " successfully..." -BackgroundColor Green -ForegroundColor Black

}

catch {

# Sending status to CP and EventLog

throw "ERROR: Could not Create AD"

}

}

end {

# Cleanup

$step001 = $null

}

}

&nbsp;

function Join-AD {

&lt;#

Function to add second AD Server

&nbsp;

Join-AD -hostname $xmlServer02.name -hostip $xmlServer02.ip -dnsip $xmlServer01.ip -domainName $xmldomain.name -adminpw $xmlServer01.adminpw

&nbsp;

#&gt;

Param(

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$hostname,

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$hostip,

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$dnsip,

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$domainName,

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$adminpw

)

begin {

# Prepair for Second AD Server

}

process {

try {

# Script Block join AD

$step001 = @"

netsh interface ipv4 add dnsserver name="Local Area Connection" address=$dnsip index=1

netdom join $hostname /domain:"$domainName" /userd:administrator /passwordd:$adminpw /REBoot

"@

&nbsp;

# Run Scriptblock

Write-Host "Adding " $hostname " to domain..." -BackgroundColor Black -ForegroundColor White

&nbsp;

Invoke-Command -ComputerName $hostip -ScriptBlock (ConvertTo-Scriptblock -String $step001) -Credential $cred

Write-Host "Domainjoin for " $hostname " successfully..." -BackgroundColor Green -ForegroundColor Black

&nbsp;

&nbsp;

}

catch {

# Sending status to CP and EventLog

throw "ERROR: Could not add System to AD"

}

}

end {

# Cleanup

$step001 = $null

}

}

&nbsp;

function Add-ADServer {

&lt;#

Function to add a second AD to the Domain

#&gt;

begin {

# Prepair for First AD Server

Write-Host "Preparing Script Block for DCPROMO " $xmlServer02.name "..." -BackgroundColor Black -ForegroundColor White

$server01ip = $xmlServer01.ip

$domainName = $xmldomain.name

$server01pw = $xmlServer01.adminpw

$domainSafemodePW = $xmldomain.safemodepw

}

process {

try {

# Script Block for First AD Server

$step001 = @"

Dcpromo /unattend /replicaOrnewDomain:replica /replicaDomainDNSName:$domainName /ConfirmGC:yes /username:administrator /Password:$server01pw /safeModeAdminPassword:$domainSafemodePW

"@

# Run Scriptblock

Write-Host "Running DCPROMO " $xmlServer02.name "..." -BackgroundColor Black -ForegroundColor White

Invoke-Command -ComputerName $xmlServer02.ip -ScriptBlock (ConvertTo-Scriptblock -String $step001) -Credential $cred

Write-Host "DCPROMO " $xmlServer02.name " successfully..." -BackgroundColor Green -ForegroundColor Black

}

catch {

throw "ERROR: Could not add Second Server to AD"

}

}

end {

# Cleanup

$step001 = $null

}

}

&nbsp;

function Add-ADOU {

&lt;#

Function to add OU to AD

&nbsp;

Add-ADOU -hostip $xmlServer01.ip -name $namedings -path $pathdings

&nbsp;

#&gt;

Param(

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$hostip,

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$name,

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$path

)

begin {

# Prepair for Second AD Server

}

process {

try {

# Script Block join AD

$step001 = @"

Import-Module ActiveDirectory

New-ADOrganizationalUnit -name "$name" -Path "$path"

"@

&nbsp;

# Run Scriptblock

Write-Host "Adding OU " $name " to " $path "..." -BackgroundColor Black -ForegroundColor White

&nbsp;

Invoke-Command -ComputerName $hostip -ScriptBlock (ConvertTo-Scriptblock -String $step001) -Credential $cred

Write-Host "OU added " $name " successfully..." -BackgroundColor Green -ForegroundColor Black

}

catch {

# Sending status to CP and EventLog

throw "ERROR: Could not add OU to AD"

}

}

end {

# Cleanup

$step001 = $null

}

}

&nbsp;

function Add-UsersfromFile {

&lt;#

Function to add OU to AD

&nbsp;

Add-UsersfromFile -hostip $xmlServer01.ip -filename $xmlData.lab.config.users.file.name -path $xmlData.lab.config.users.file.path

&nbsp;

#&gt;

Param(

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$hostip,

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$SamAccountName,

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$UserPrincipalName,

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$name,

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$DisplayName,

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$GivenName,

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$SurName,

[Parameter(

Mandatory = $false,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$Manager,

[Parameter(

Mandatory = $false,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$Department,

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$path

)

begin {

&nbsp;

}

process {

try {

# Script Block join AD

$step001 = @"

Import-Module ActiveDirectory

New-ADUser -SamAccountName $SamAccountName -UserPrincipalName $userprinicpalname -DisplayName $displayname -GivenName $GivenName -SurName $SurName -Path "$path" -AccountPassword (ConvertTo-SecureString "test41;" -AsPlainText -force)

"@

&nbsp;

# Run Scriptblock

Write-Host "Adding Users " $userprinicpalname " to " $path "..." -BackgroundColor Black -ForegroundColor White

&nbsp;

Invoke-Command -ComputerName $hostip -ScriptBlock (ConvertTo-Scriptblock -String $step001) -Credential $cred

Write-Host "Users " $userprinicpalname " added successfully..." -BackgroundColor Green -ForegroundColor Black

}

catch {

# Sending status to CP and EventLog

throw "ERROR: Could not add Users to AD"

}

}

end {

# Cleanup

$step001 = $null

}

}

&nbsp;

&nbsp;

function WaitFor-Host {

&lt;#

Function to wait for Host after Reboot

&nbsp;

WaitFor-Host -hostip $xmlServer01.ip -service servicename

&nbsp;

#&gt;

Param(

[Parameter(

Mandatory = $true,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$hostip,

[Parameter(

Mandatory = $false,

ParameterSetName = '',

ValueFromPipeline = $true)]

[string]$service

)

begin {

#

}

process {

try {

# Wait until Server is offline

Write-Host "Waiting for Reboot " $hostip "..." -BackgroundColor Black -ForegroundColor White

Start-Sleep -Seconds 10

&nbsp;

# Wait for Server Reboot

Write-Host "Waiting for Host " $hostip "..." -BackgroundColor Black -ForegroundColor White

while (!(Test-Connection $hostip -quiet)) {

Write-Host 'Unreachable!'

}

Write-Host "Server up..." -BackgroundColor Green -ForegroundColor Black

Start-Sleep -Seconds 30

}

catch {

# Sending status to CP and EventLog

throw "ERROR: Waiting for reboot failed"

}

}

end {

}

}

&nbsp;

&nbsp;

&nbsp;

&nbsp;

#endregion

&nbsp;

&nbsp;

&nbsp;

&nbsp;

#region [MAIN BLOCK]

&nbsp;

# Enable ICMP

Enable-ICMP -hostip $xmlServer01.ip

Enable-ICMP -hostip $xmlServer02.ip

&nbsp;

# Create first AD Server

Create-ADServer

Start-Sleep -Seconds 30

WaitFor-Host -hostip $xmlServer01.ip

&nbsp;

# Add Second AD Server to Domain

Join-AD -hostname $xmlServer02.name -hostip $xmlServer02.ip -dnsip $xmlServer01.ip -domainName $xmldomain.name -adminpw $xmlServer01.adminpw

Start-Sleep -Seconds 30

WaitFor-Host -hostip $xmlServer02.ip

&nbsp;

# Run DCPROMO on Second AD Server

Add-ADServer

&nbsp;

# Add OUs to Domain

foreach ($ou in $xmlOUS.ou){

Add-ADOU -hostip $xmlServer01.ip -name $ou.name -path $ou.path

}

&nbsp;

&nbsp;

# Add Users to Domain

foreach ($file in $xmlData.lab.config.users.file){

$tempfile = ".\" + $file.name

Import-Csv $tempfile | Foreach-Object {

$userprinicpalname = $_.SamAccountName + "@" + $xmlDomain.name

Add-UsersfromFile -hostip $xmlServer01.ip -SamAccountName $_.SamAccountName -UserPrincipalName $userprinicpalname -Name $_.name -DisplayName $_.name -GivenName $_.GivenName -SurName $_.SurName -Manager $_.Manager -Department $_.Department -Path $file.path

}

}

&nbsp;

&nbsp;

&nbsp;

# Add Members to Domain

foreach ($member in $xmlData.lab.config.members.member){

Join-AD -hostname $member.name -hostip $member.ip -dnsip $xmlServer01.ip -domainName $xmldomain.name -adminpw $xmlServer01.adminpw

}

&nbsp;

#endregion
</pre>
<p>&nbsp;</p>
<!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com --><div class="shr-publisher-3024"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2011/12/automated-active-directory-deployment-with-powershell/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PowerShell 3.0: Show-Command</title>
		<link>http://www.thomasmaurer.ch/2011/11/powershell-3-0-show-command/</link>
		<comments>http://www.thomasmaurer.ch/2011/11/powershell-3-0-show-command/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 07:54:48 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Windows Server 8]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell 3.0]]></category>
		<category><![CDATA[Show-Command]]></category>
		<category><![CDATA[Windows Powershell]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=2896</guid>
		<description><![CDATA[Just a simple note about a new cmdlet in PowerShell 3.0. Show-Command is something very useful if you try out a new PowerShell Command. It shows all the options and possible parameters you have with the cmdlet. Show-Command Get-Childitem &#160;]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='small' href='http://www.thomasmaurer.ch/2011/11/powershell-3-0-show-command/'></g:plusone></div><div class='dd_button'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.thomasmaurer.ch/2011/11/powershell-3-0-show-command/" data-count="horizontal" data-text="PowerShell 3.0: Show-Command" data-via="thomasmaurer" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class='dd_button'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.thomasmaurer.ch%2F2011%2F11%2Fpowershell-3-0-show-command%2F&amp;locale=en_US&amp;layout=button_count&amp;action=like&amp;width=92&amp;height=20&amp;colorscheme=light' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:92px; height:20px;' allowTransparency='true'></iframe></div></div><div style='clear:both'></div></div><div style='clear:both'></div><p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/powershell1.png" rel="lightbox[2896]"><img class="aligncenter size-medium wp-image-2607" title="Powershell" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/powershell1-300x95.png" alt="Powershell" width="300" height="95" /></a></p>
<p>Just a simple note about a new cmdlet in PowerShell 3.0. Show-Command is something very useful if you try out a new PowerShell Command. It shows all the options and possible parameters you have with the cmdlet.</p>
<pre>Show-Command Get-Childitem</pre>
<p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2011/11/Show-Command.png" rel="lightbox[2896]"><img class="aligncenter size-medium wp-image-2897" title="Show-Command" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/11/Show-Command-300x223.png" alt="Show-Command" width="300" height="223" /></a></p>
<p>&nbsp;</p>
<!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com --><div class="shr-publisher-2896"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2011/11/powershell-3-0-show-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell: Convert String to Scriptblock</title>
		<link>http://www.thomasmaurer.ch/2011/11/powershell-convert-string-to-scriptblock/</link>
		<comments>http://www.thomasmaurer.ch/2011/11/powershell-convert-string-to-scriptblock/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 16:49:03 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[Convert String to Scriptblock]]></category>
		<category><![CDATA[Invoke-Command]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Remoting]]></category>
		<category><![CDATA[Scriptblock]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=2836</guid>
		<description><![CDATA[If you use PowerShell remoting in some scripts you will se you cannot use a string to send it with the Invoke-Command cmdlet. So you can simple convert a String to a Scriptblock  $scriptBlock = [Scriptblock]::Create($string) Now here an example &#8230; <a href="http://www.thomasmaurer.ch/2011/11/powershell-convert-string-to-scriptblock/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='small' href='http://www.thomasmaurer.ch/2011/11/powershell-convert-string-to-scriptblock/'></g:plusone></div><div class='dd_button'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.thomasmaurer.ch/2011/11/powershell-convert-string-to-scriptblock/" data-count="horizontal" data-text="Powershell: Convert String to Scriptblock" data-via="thomasmaurer" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class='dd_button'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.thomasmaurer.ch%2F2011%2F11%2Fpowershell-convert-string-to-scriptblock%2F&amp;locale=en_US&amp;layout=button_count&amp;action=like&amp;width=92&amp;height=20&amp;colorscheme=light' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:92px; height:20px;' allowTransparency='true'></iframe></div></div><div style='clear:both'></div></div><div style='clear:both'></div><p><a href="http://www.thomasmaurer.ch/2011/01/run-remote-powershell-commands-on-multiple-standalone-computers/" title="Run Remote Powershell Commands on multiple standalone Computers" target="_blank"></a>If you use PowerShell remoting in some scripts you will se you cannot use a string to send it with the Invoke-Command cmdlet.</p>
<p>So you can simple convert a String to a Scriptblock</p>
<pre> $scriptBlock = [Scriptblock]::Create($string) </pre>
<p>Now here an example</p>
<pre>$remoteCommand =
@"
Import-Module ActiveDirectory
New-ADOrganizationalUnit -name
"@

$scriptBlock = [Scriptblock]::Create($remoteCommand)

Invoke-Command -ComputerName AD01 -ScriptBlock $scriptBlock
</pre>
<p>Basically you could create a function for that.</p>
<pre>
function ConvertTo-Scriptblock  {
&lt;#
 Function to Convert a String into a Script Block
#&gt;
	Param(
        [Parameter(
            Mandatory = $true,
            ParameterSetName = &#039;&#039;,
            ValueFromPipeline = $true)]
            [string]$string
        )
       $scriptBlock = [scriptblock]::Create($string)
       return $scriptBlock
}</pre>
<!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com --><div class="shr-publisher-2836"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2011/11/powershell-convert-string-to-scriptblock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell: Ping IP range</title>
		<link>http://www.thomasmaurer.ch/2011/11/powershell-ping-ip-range/</link>
		<comments>http://www.thomasmaurer.ch/2011/11/powershell-ping-ip-range/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 16:31:04 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[IP range]]></category>
		<category><![CDATA[Ping]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=2829</guid>
		<description><![CDATA[Some you need to know which IP in a specific range is already in use. With Windows PowerShell there is a simple way to ping a IP range. You can use the .Net class System.Net.Networkinformation.Ping to do this. $ping = &#8230; <a href="http://www.thomasmaurer.ch/2011/11/powershell-ping-ip-range/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='small' href='http://www.thomasmaurer.ch/2011/11/powershell-ping-ip-range/'></g:plusone></div><div class='dd_button'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.thomasmaurer.ch/2011/11/powershell-ping-ip-range/" data-count="horizontal" data-text="PowerShell: Ping IP range" data-via="thomasmaurer" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class='dd_button'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.thomasmaurer.ch%2F2011%2F11%2Fpowershell-ping-ip-range%2F&amp;locale=en_US&amp;layout=button_count&amp;action=like&amp;width=92&amp;height=20&amp;colorscheme=light' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:92px; height:20px;' allowTransparency='true'></iframe></div></div><div style='clear:both'></div></div><div style='clear:both'></div><p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/powershell1.png" rel="lightbox[2829]"><img class="aligncenter size-medium wp-image-2607" title="Powershell" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/powershell1-300x95.png" alt="Powershell" width="300" height="95" /></a></p>
<p>Some you need to know which IP in a specific range is already in use. With Windows PowerShell there is a simple way to ping a IP range.</p>
<p>You can use the .Net class System.Net.Networkinformation.Ping to do this.</p>
<pre>

$ping = New-Object System.Net.Networkinformation.Ping
1..254 | % { $ping.send(“192.168.100.$_”) | select address, status } 
</pre>
<!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com --><div class="shr-publisher-2829"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2011/11/powershell-ping-ip-range/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Commands for Windows Server Core &amp; Hyper-V Core Server</title>
		<link>http://www.thomasmaurer.ch/2011/10/commands-for-windows-server-core-hyper-v-core-server/</link>
		<comments>http://www.thomasmaurer.ch/2011/10/commands-for-windows-server-core-hyper-v-core-server/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 14:45:15 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[Hyper-V]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Server Core]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Windows Server 2008 R2]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[cmd]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[commandline]]></category>
		<category><![CDATA[Core Server]]></category>
		<category><![CDATA[Hyper-V Server]]></category>
		<category><![CDATA[KTSI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[sconfig]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=2814</guid>
		<description><![CDATA[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 &#8230; <a href="http://www.thomasmaurer.ch/2011/10/commands-for-windows-server-core-hyper-v-core-server/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='small' href='http://www.thomasmaurer.ch/2011/10/commands-for-windows-server-core-hyper-v-core-server/'></g:plusone></div><div class='dd_button'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.thomasmaurer.ch/2011/10/commands-for-windows-server-core-hyper-v-core-server/" data-count="horizontal" data-text="Commands for Windows Server Core & Hyper-V Core Server" data-via="thomasmaurer" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class='dd_button'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.thomasmaurer.ch%2F2011%2F10%2Fcommands-for-windows-server-core-hyper-v-core-server%2F&amp;locale=en_US&amp;layout=button_count&amp;action=like&amp;width=92&amp;height=20&amp;colorscheme=light' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:92px; height:20px;' allowTransparency='true'></iframe></div></div><div style='clear:both'></div></div><div style='clear:both'></div><p>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.</p>
<p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2011/10/coreserver.png" rel="lightbox[2814]"><img class="aligncenter size-medium wp-image-2821" title="Windows Server Core" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/10/coreserver-300x152.png" alt="Windows Server Core" width="300" height="152" /></a></p>
<h1>Networking</h1>
<p><strong>Set Hostname</strong></p>
<pre>netdom renamecomputer %COMPUTERNAME% /NewName:&lt;NewComputerName&gt; </pre>
<p><strong>Join Domain</strong></p>
<pre>netdom join %COMPUTERNAME% /domain:&lt;DomainName&gt; /userd:&lt;UserName&gt; /passwordd:*</pre>
<p><strong>Remove Domain</strong></p>
<pre>netdom remove</pre>
<p><strong>Rename Network Interface</strong></p>
<pre>netsh interface set interface name=”old name” newname=”new name”</pre>
<p><strong>Configure IP Address</strong></p>
<pre>netsh interface ipv4 set address name=”&lt;Interface Name&gt;” source=static address=&lt;IPAddress&gt; mask=&lt;SubnetMask&gt; gateway=&lt;DefaultGateway&gt;</pre>
<p><strong>Configure DNS Servers</strong></p>
<pre>netsh interface ipv4 add dnsserver name=”&lt;Interface Name&gt;” address=&lt;DNS Server IP&gt; index=1</pre>
<p><strong>Disable Firewall (not recommended)</strong></p>
<pre>netsh advfirewall set allprofiles state off</pre>
<p>&nbsp;</p>
<h1>Remoting</h1>
<p><strong>Enable PowerShell Remoting</strong></p>
<pre>Enable-PSRemoting</pre>
<p><strong>Enable Remotedesktop</strong></p>
<pre>netsh advfirewall firewall set rule group=”remote desktop” new enable=yes</pre>
<p><strong>Enable Remote Administration</strong></p>
<pre>advfirewall firewall set rule group=”Remote Administration” new enable=yes</pre>
<p><strong>Enable Remote Firewall Administration</strong></p>
<pre>netsh advfirewall firewall set rule group=”Windows Firewall Remote Management” new enable=yes</pre>
<p><strong>Enable ICMP (Ping)</strong></p>
<pre>netsh firewall set icmpsetting 8</pre>
<p><strong>Enable Remote Disk Management</strong></p>
<pre>netsh advfirewall firewall set rule group=”Remote Volume Management” new enable=yes</pre>
<p>&nbsp;</p>
<h1>Licensing</h1>
<p><strong>Enter License key</strong></p>
<pre>slmgr.vbs -ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX</pre>
<p><strong>Activate Windows</strong></p>
<pre>slmgr.vbs -ato</pre>
<p>&nbsp;</p>
<h1>Windows Update</h1>
<p><strong>Enable automatic updates</strong></p>
<pre>cscript C:'Windows'System32'Scregedit.wsf /au 4</pre>
<p><strong>Disable automatic updates</strong></p>
<pre>cscript C:'Windows'System32'Scregedit.wsf /au 1</pre>
<p>&nbsp;</p>
<h1>Roles &amp; Features</h1>
<p><strong>Get availibale features &amp; roles</strong></p>
<pre>Dism /online /get-features /format:table</pre>
<p><strong>Enable feature &amp; roles</strong></p>
<pre>Dism /online /enable-feature /featurename:&lt;featurename&gt;</pre>
<p>&nbsp;</p>
<h1>Basics</h1>
<p><strong>Change Administrator password</strong></p>
<pre>net user administrator *</pre>
<p><strong>Restart Computer</strong></p>
<pre>shutdown /r /t 0</pre>
<p><strong>Logoff</strong></p>
<pre>logoff</pre>
<p>More information about Server Core: <a title="Serevr Core Technet" href="http://technet.microsoft.com/en-us/library/cc753802(WS.10).aspx" target="_blank">TechNet</a></p>
<!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com --><div class="shr-publisher-2814"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2011/10/commands-for-windows-server-core-hyper-v-core-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Change Office 365 password expiration policy</title>
		<link>http://www.thomasmaurer.ch/2011/10/change-office-365-password-expiration-policy/</link>
		<comments>http://www.thomasmaurer.ch/2011/10/change-office-365-password-expiration-policy/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 08:17:32 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Exchange Online]]></category>
		<category><![CDATA[Hosting]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Lync Online]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Office365]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[SharePoint Online]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Office 365]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[Password Policy]]></category>
		<category><![CDATA[Policy]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Set-MsolUser]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=2735</guid>
		<description><![CDATA[The default password expiration policy of Office 365 is set to 90 days. That means that users have to change their password every 90 days. I think basicly this is a good and secure policy but maybe your company has other &#8230; <a href="http://www.thomasmaurer.ch/2011/10/change-office-365-password-expiration-policy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='small' href='http://www.thomasmaurer.ch/2011/10/change-office-365-password-expiration-policy/'></g:plusone></div><div class='dd_button'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.thomasmaurer.ch/2011/10/change-office-365-password-expiration-policy/" data-count="horizontal" data-text="Change Office 365 password expiration policy" data-via="thomasmaurer" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class='dd_button'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.thomasmaurer.ch%2F2011%2F10%2Fchange-office-365-password-expiration-policy%2F&amp;locale=en_US&amp;layout=button_count&amp;action=like&amp;width=92&amp;height=20&amp;colorscheme=light' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:92px; height:20px;' allowTransparency='true'></iframe></div></div><div style='clear:both'></div></div><div style='clear:both'></div><p><img class="aligncenter size-medium wp-image-1928" title="office365" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/05/office365-300x179.jpg" alt="office365" width="300" height="179" /></p>
<p>The default password expiration policy of <a title="Office 365" href="http://www.office365.com" target="_blank">Office 365</a> is set to 90 days. That means that users have to change their password every 90 days. I think basicly this is a good and secure policy but maybe your company has other security policy or for some other reason you have to deactivate this. We can change this setting through PowerShell with the MicrosoftOnline PowerShell Module.</p>
<ol>
<li>First connect to Office 365 <a title="Office 365 PowerShell" href="http://www.thomasmaurer.ch/2011/07/office-365-how-to-connect-with-powershell/" target="_blank">via PowerShell more on this here</a></li>
<li>Now you can use the following cmdlet
<pre>Set-MsolUser -UserPrincipalName user@contoso.com –PasswordNeverExpires $true</pre>
</li>
</ol>
<p>&nbsp;</p>
<!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com --><div class="shr-publisher-2735"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2011/10/change-office-365-password-expiration-policy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick note on PowerShell 3.0</title>
		<link>http://www.thomasmaurer.ch/2011/09/quick-note-on-powershell-3-0/</link>
		<comments>http://www.thomasmaurer.ch/2011/09/quick-note-on-powershell-3-0/#comments</comments>
		<pubDate>Wed, 28 Sep 2011 18:20:21 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell 3.0]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=2646</guid>
		<description><![CDATA[Today I had some time to test some of the new Windows PowerShell 3.0 feature and changes. And after playing a while with the Windows PowerShell 3.0 CTP I have to say Microsoft did besides the big new features, like &#8230; <a href="http://www.thomasmaurer.ch/2011/09/quick-note-on-powershell-3-0/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='small' href='http://www.thomasmaurer.ch/2011/09/quick-note-on-powershell-3-0/'></g:plusone></div><div class='dd_button'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.thomasmaurer.ch/2011/09/quick-note-on-powershell-3-0/" data-count="horizontal" data-text="Quick note on PowerShell 3.0" data-via="thomasmaurer" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class='dd_button'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.thomasmaurer.ch%2F2011%2F09%2Fquick-note-on-powershell-3-0%2F&amp;locale=en_US&amp;layout=button_count&amp;action=like&amp;width=92&amp;height=20&amp;colorscheme=light' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:92px; height:20px;' allowTransparency='true'></iframe></div></div><div style='clear:both'></div></div><div style='clear:both'></div><p><img class="aligncenter size-full wp-image-2607" title="Powershell" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/powershell1.png" alt="Powershell" width="541" height="172" /></p>
<p>Today I had some time to test some of the new Windows PowerShell 3.0 feature and changes. And after playing a while with the <a title="Windows Management Framework 3.0 Community Technology Preview" href="http://www.thomasmaurer.ch/2011/09/windows-management-framework-3-0-community-technology-preview/" target="_blank">Windows PowerShell 3.0 CTP</a> I have to say Microsoft did besides the big new features, like workflows, a lot of small but really important improvements.</p>
<p>First I will show you two very small but very cool things which make working with PowerShell a lot easier.</p>
<p>New help view, which I really like. Here quick PowerShell 2.0 versus PowerShell 3.0:</p>

<a href='http://www.thomasmaurer.ch/2011/09/quick-note-on-powershell-3-0/powershell-2-0-help/' title='powershell 2.0 help'><img width="150" height="150" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/powershell-2.0-help-150x150.png" class="attachment-thumbnail" alt="powershell 2.0 help" title="powershell 2.0 help" /></a>
<a href='http://www.thomasmaurer.ch/2011/09/quick-note-on-powershell-3-0/powershell-3-0-help/' title='powershell 3.0 help'><img width="150" height="150" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/powershell-3.0-help-150x150.png" class="attachment-thumbnail" alt="powershell 3.0 help" title="powershell 3.0 help" /></a>
<a href='http://www.thomasmaurer.ch/2011/09/quick-note-on-powershell-3-0/powershell-2-0-vs-3-0-childitem/' title='powershell 2.0 vs 3.0 childitem'><img width="150" height="150" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/powershell-2.0-vs-3.0-childitem-150x150.png" class="attachment-thumbnail" alt="powershell 2.0 vs 3.0 childitem" title="powershell 2.0 vs 3.0 childitem" /></a>

<p>Second I would like you to show how they simplified PowerShell for daily use. Here Get-Childitem for an example:</p>
<p>In PowerShell 2.0:</p>
<pre>
Get-Childitem | Where {$_.name -eq "Desktop"}
</pre>
<p>In PowerShell 3.0 you can do this now much friendlier:</p>
<pre>
Get-Childitem | where name -eq Desktop
</pre>
<p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/powershell-2.0-vs-3.0-childitem.png" rel="lightbox[2646]"><img class="aligncenter size-medium wp-image-2649" title="powershell 2.0 vs 3.0 childitem" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/powershell-2.0-vs-3.0-childitem-225x300.png" alt="powershell 2.0 vs 3.0 childitem" width="225" height="300" /></a></p>
<!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com --><div class="shr-publisher-2646"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2011/09/quick-note-on-powershell-3-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Management Framework 3.0 Community Technology Preview</title>
		<link>http://www.thomasmaurer.ch/2011/09/windows-management-framework-3-0-community-technology-preview/</link>
		<comments>http://www.thomasmaurer.ch/2011/09/windows-management-framework-3-0-community-technology-preview/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 14:56:29 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Windows Server 2008 R2]]></category>
		<category><![CDATA[Windows Server 8]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[CTP]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell 3.0]]></category>
		<category><![CDATA[version]]></category>
		<category><![CDATA[Windows Management Framework]]></category>
		<category><![CDATA[Windows Powershell]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=2603</guid>
		<description><![CDATA[&#160; Some days ago the Microsoft Powershell Team released the Community Technology Preview of the Windows Management Framework 3.0 which includes Windows PowerShell v3. You can download the the CTP1 here and it requires Windows 7 SP1 or Windows Server &#8230; <a href="http://www.thomasmaurer.ch/2011/09/windows-management-framework-3-0-community-technology-preview/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='small' href='http://www.thomasmaurer.ch/2011/09/windows-management-framework-3-0-community-technology-preview/'></g:plusone></div><div class='dd_button'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.thomasmaurer.ch/2011/09/windows-management-framework-3-0-community-technology-preview/" data-count="horizontal" data-text="Windows Management Framework 3.0 Community Technology Preview" data-via="thomasmaurer" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class='dd_button'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.thomasmaurer.ch%2F2011%2F09%2Fwindows-management-framework-3-0-community-technology-preview%2F&amp;locale=en_US&amp;layout=button_count&amp;action=like&amp;width=92&amp;height=20&amp;colorscheme=light' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:92px; height:20px;' allowTransparency='true'></iframe></div></div><div style='clear:both'></div></div><div style='clear:both'></div><p>&nbsp;</p>
<p><img class="aligncenter size-full wp-image-2607" title="Powershell" src="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/powershell1.png" alt="Powershell" width="541" height="172" /></p>
<p>Some days ago the Microsoft Powershell Team released the Community Technology Preview of the Windows Management Framework 3.0 which includes Windows PowerShell v3. You can <a title="Windows Management Framework CPT download" href="http://www.microsoft.com/download/en/details.aspx?id=27548" target="_blank">download the the CTP1 here</a> and it requires Windows 7 SP1 or Windows Server 2008 R2 with SP1.</p>
<p>You can use very easy both PowerShell versions sie by site.</p>
<pre>
powershell.exe -Version 3.0

powershell.exe -Version 2.0
</pre>
<p>But the Windows Management Framework 3.0 CTP1 does not only includes PowerShell 3, it also contains new versions of WMI, WinRM and the new Windows PowerShell Webservice.</p>
<h1>Windows PowerShell 3.0</h1>
<ul>
<li><strong>Workflows </strong><br />
Workflows that run long-running activities (in sequence or in parallel) to perform complex, larger management tasks, such as multi-machine application provisioning. Using the Windows Workflow Foundation at the command line, Windows PowerShell workflows are repeatable, parallelizable, interruptible, and recoverable.</li>
<li><strong>Robust Sessions </strong><br />
Robust sessions that automatically recover from network failures and interruptions and allow you to disconnect from the session, shut down the computer, and reconnect from a different computer without interrupting the task.</li>
<li><strong>Scheduled Jobs<br />
</strong>Scheduled jobs that run regularly or in response to an event.</li>
<li><strong>Delegated Administration</strong><br />
Commands that can be executed with a delegated set of credentials so users with limited permissions can run critical jobs</li>
<li><strong>Simplified Language Syntax<br />
</strong>Simplified language syntax that make commands and scripts look a lot less like code and a lot more like natural language.</li>
<li><strong>Cmdlet Discovery</strong><br />
Improved cmdlet discovery and automatic module loading that make it easier to find and run any of the cmdlets installed on your computer.</li>
<li><strong>Show-Command</strong><br />
Show-Command, a cmdlet and ISE Add-On that helps users find the right cmdlet, view its parameters in a dialog box, and run it.</li>
</ul>
<h1>WMI</h1>
<ul>
<li><strong>A new provider development model</strong><br />
This new model brings down the cost of provider development and removes the dependency on COM.</li>
<li><strong>A new MI Client API to perform standard CIM operations. </strong><br />
The API can be used to interact with any standard WsMan + CIMOM implementation, allowing management applications on Windows to manage non-Windows computers.</li>
<li><strong>The ability to write Windows PowerShell cmdlets in native code</strong><br />
The new WMI Provider APIs supports an extended Windows PowerShell semantics API allowing you to provide rich Windows PowerShell semantics. e.g., Verbose, Error, Warning, WhatIf, Confirm, Progress</li>
</ul>
<h1>WinRM</h1>
<ul>
<li><strong>Connections are more robust </strong><br />
Session disconnect and reconnect, with or without client session reconstruction, allows long-running tasks to continue even when the session in which they were started is closed and the client computer is shut down. This feature also allows administrators to reconnect from different computers to check the status of remote running tasks and get results.</li>
<li><strong>Connections are more resilient</strong><br />
In Windows PowerShell 3.0 CTP1, connections can survive short-term network failures; the client-server connection is not severed at the first sign of trouble. If network problems persist, the client is safely disconnected and can reconnect by using the Connect-PSSession or Receive-PSSession cmdlets.</li>
</ul>
<h1>Windows PowerShell Web Service</h1>
<p>Windows PowerShell Web Service enables an administrator to expose a set of PowerShell cmdlets as a RESTful web endpoint accessible via the Open Data Protocol (OData). This provides remote access to invoke cmdlets from both Windows and non-Windows clients.</p>
<p>You can get more Information about the Windows Management Framework 3.0 Community Technology Preview on the <a title="Powershell Team Blo" href="http://blogs.msdn.com/b/powershell/archive/2011/09/20/windows-management-framework-3-0-community-technology-preview-ctp-1-available-for-download.aspx" target="_blank">Windows PowerShell Team Blog</a>.</p>
<!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com --><div class="shr-publisher-2603"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2011/09/windows-management-framework-3-0-community-technology-preview/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hyper-V 3: Attach multiple VHDs via PowerShell</title>
		<link>http://www.thomasmaurer.ch/2011/09/hyper-v-3-attach-multiple-vhds-via-powershell/</link>
		<comments>http://www.thomasmaurer.ch/2011/09/hyper-v-3-attach-multiple-vhds-via-powershell/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 15:40:40 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[Hyper-V]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Windows Server 8]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Attach]]></category>
		<category><![CDATA[Hyper-V 3]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Powershell v3]]></category>
		<category><![CDATA[VHD]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=2595</guid>
		<description><![CDATA[We are already testing some Windows Server 8 installations and to test some of the new storage features I needed to attach a lot of VHDs to a Virtual Machine. Now with this Windows PowerShell script its very easy and &#8230; <a href="http://www.thomasmaurer.ch/2011/09/hyper-v-3-attach-multiple-vhds-via-powershell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='small' href='http://www.thomasmaurer.ch/2011/09/hyper-v-3-attach-multiple-vhds-via-powershell/'></g:plusone></div><div class='dd_button'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.thomasmaurer.ch/2011/09/hyper-v-3-attach-multiple-vhds-via-powershell/" data-count="horizontal" data-text="Hyper-V 3: Attach multiple VHDs via PowerShell" data-via="thomasmaurer" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class='dd_button'><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.thomasmaurer.ch%2F2011%2F09%2Fhyper-v-3-attach-multiple-vhds-via-powershell%2F&amp;locale=en_US&amp;layout=button_count&amp;action=like&amp;width=92&amp;height=20&amp;colorscheme=light' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:92px; height:20px;' allowTransparency='true'></iframe></div></div><div style='clear:both'></div></div><div style='clear:both'></div><p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/Powershell-Hyper-V-Attach-VHDs.png" rel="lightbox[2595]"><img src="http://www.thomasmaurer.ch/wp-content/uploads/2011/09/Powershell-Hyper-V-Attach-VHDs-300x176.png" alt="Powershell Hyper-V Attach VHDs" title="Powershell Hyper-V Attach VHDs" width="300" height="176" class="aligncenter size-medium wp-image-2599" /></a><br />
We are already testing some Windows Server 8 installations and to test some of the new storage features I needed to attach a lot of VHDs to a Virtual Machine. Now with this Windows PowerShell script its very easy and fast.</p>
<p>Important:</p>
<ul>
<li>Needs Windows Server 8 (Developer Preview)</li>
<li>Needs Hyper-V 3 (Inculded in Windows Server 8 )</li>
<li>Needs PowerShell v3 (Also included in Windows Server 8 )</li>
</ul>
<pre>
$filePath = "\\storage01\VHDStorage\Virtual Hard Disks\"
$fileName = "server03-disk" # Your VHD will be called yourvhdnameX.vhdx (X = Number)
$serverName = "server03"
$controllerNumber = "0"
[int64]$vHDSizeGB = "100" # in GB
$vHDFormat = "vhdx" # vhdx or vhd
$vHDType = "Dynamic"
$numberofVHDs = "8"

for ($i=1;$i -le $numberofVHDs; $i++){

    $vHDPath = $filePath + $fileName + $i + "." + $vHDFormat
    New-VHD -Path $vHDPath -SizeBytes ($vHDSizeGB * 1073741824) -VHDFormat $vHDFormat -VHDType $vHDType
    Add-VMHardDiskDrive -VMName $serverName -ControllerType SCSI -ControllerNumber $controllerNumber -Path $vHDPath

}
</pre>
<p>The best thing overall is how you fast you can create such scripts with PowerShell v3. It took me like 10-12 minutes to get this thing done, and if you think how I would have to create and attach all of those VHDs with the wizard, I saved myself a lot of time.</p>
<!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com --><div class="shr-publisher-2595"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2011/09/hyper-v-3-attach-multiple-vhds-via-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.509 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-07 00:03:32 -->
<!-- Compression = gzip -->
