How to: Create multiple VM’s in Hyper-V within a few seconds

Automation is one of my favorite things. Some actions are just time consuming, so let’s automate these things!! For example, create a demo environment within Hyper-V. This environment needs 8 VM’s. With a few lines of code, this is realy easy to automate, off course with PowerShell.


## Create 8 Gen2 Virtual Machines
## 4 vCPU per VM
## 1 GB per VM
## C: drive 50 GB Dynamic
## D: drive 50 GB Dynamic
## NIC renamed to MGMT
$vSwitchName01 = "NIC - PRI"
$InstallRoot = "E:\DEMO"
$VMName = "HV-0"

## How much VM's 1..8 = 8 VM's
1..4 | % {
New-VHD -Path ($InstallRoot + "\$VMName" + "$_\" + "\$VMName" + "$_" + "_C.vhdx") -SizeBytes 50GB -Dynamic
New-VHD -Path ($InstallRoot + "\$VMName" + "$_\" + "\$VMName" + "$_" + "_D.vhdx") -SizeBytes 50GB -Dynamic
New-VM -VHDPath ($InstallRoot + "\$VMName" + "$_\" + "\$VMName" + "$_" + "_C.vhdx") -Generation 2 -MemoryStartupBytes 1GB -Name ("$VMName" + "$_") -Path $InstallRoot -SwitchName $vSwitchName01

Set-VMProcessor -VMName ("$VMName" + "$_") -Count 4
Set-VM -VMName ("$VMName" + "$_") -AutomaticStopAction ShutDown -AutomaticStartAction StartIfRunning
Enable-VMIntegrationService ("$VMName" + "$_") -Name "Guest Service Interface"

Rename-VMNetworkAdapter -VMName ("$VMName" + "$_") -NewName "MGMT"
Set-VMNetworkAdapter -VMName ("$VMName" + "$_") -Name "MGMT" -DeviceNaming On

Add-VMScsiController -VMName ("$VMName" + "$_")
Add-VMHardDiskDrive -VMName ("$VMName" + "$_") -ControllerType SCSI -ControllerNumber 1 -ControllerLocation 0 -Path ($InstallRoot + "\$VMName" + "$_\" + "\$VMName" + "$_" + "_D.vhdx")

Start-VM -Name ("$VMName" + "$_") | Out-Null
}

Within a few seconds, I’ve 8 VM’s up and running.

2016-03-23_10h10_00    2016-03-23_10h10_44    2016-03-23_10h11_23

/ Happy Automation!

How to: Enable RDP during Task Sequence with SCCM 2012 R2

I quiet often receive the question how to enable Remote Desktop (RDP) access on a server during a task sequence in SCCM 2012 or 2012 R2. Because by default RDP is not enabled, it could be realy handy to enable RDP access to control your server remotely. There’re a whole bunch of tools to manage your server(s) remotely, but still RDP could be ncessary.

1.) Create a new package with the source location to your script directory.
2.) Create a new package with a program and use the following command:
Powershell.exe -ExecutionPolicy Unrestricted -NoProfile -File Enable-RDP.ps1
3.) The PowerShell script ‘Enable-RDP.ps1’ contains the following code. See in this post below.
4.) Insert the script in your task sequence

##
## Enable RDP
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -Value 0
##
## Enable Firewall Rule
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
##
## Enable RDP Authentication
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "UserAuthentication" -Value 0

2015-11-27_09h03_02    2015-11-27_09h03_21    2015-11-27_09h34_03

Message tracking in Microsoft Exchange 2013….the easy way!

 

In Microsoft Exchange 2010 there was a very easy and powerfull tool, message tracking viewer. With this graphical tool you could track any message within your Exchange organization.

With Exchange 2013, the message tracking is not graphical anymore. So it’s not that easy to track some messages. The new way to go is Windows PowerShell! With the following example, you can easy create a overview of all the messages in your Exchange environment.

Get-MessageTrackingLog -ResultSize Unlimited -Start “Jul 15 2015″ | Out-GridView -Title “Exchange SMTP tracking log”

 

2015-07-15_12h37_30

You can create a search filter based on, for example: EventID, Sender, Recipients or Subject.

 

How to: View configured mailbox quota’s in Exchange 2010/2013 using Out-GridView

When you’ve configured mailbox quota’s within your Exchange 2010/2013 environment, you’ve to check the configuration sometimes. Using Microsoft PowerShell, you can watch the current configuration within a few second, so this is extremely powerfull!! But, when you have to query for some specific user or result, it’s not that easy.

There’s a very usefull command within PowerShell that I’m using almost for all my scripts….Out-GridView. When using the parameter Out-GridView, the results are not showing within the PowerShell screen, but in a separate window! Within this window, you can very easy add some search criteria….for example: specific user, quota or an overview per database.

One requirement is that the Windows Feature “Windows PowerShell Integrated Scripting Environment (ISE)” is installed on the Exchange servers or mangement server from where you’re running the commands.

1.) Open the Exchange Management Shell (EMS)
2.) For an overview of the current mailbox quota, use the following command.
Get-Mailbox -Identity mswinkels | ft Name, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota
3.) The results of this command is shown within the PowerShell window
4.) Now we’re running the same command, but replace “ft” (format-table) with “select” and add the parameter “Out-GridView”
Get-Mailbox -Identity mswinkels | Select Name, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota | Out-GridView
5.) Now the results are in a separate window! Extreme usefull when you’ve have to search for a specific result or results.

25-06-2015 10-11-47    25-06-2015 10-13-47    25-06-2015 10-15-00

25-06-2015 10-16-22    25-06-2015 10-20-51    25-06-2015 10-21-12

How to: Removing Windows 8.1 Modern Apps with PowerShell

When you install a default Windows 8.1 machine, there’re a few modern apps available. In some environments, you want
to remove these modern apps for your users.

With the following steps, you can delete specific apps or all the modern apps.

1.) To get a overview off all the package, use the following command:
Get-AppxPackage | ft Name, PackageFullName -AutoSize
2.) Let’s remove the Finance modern app
Remove-AppxPackage -Package Microsoft.BingFinance_3.0.1.172_x64__8wekyb3d8bbwe -Confirm:$false
3.) Return to the start menu and now you’ll see the Finance app is gone
4.) To remove all the modern apps, use the following command:
Get-AppxPackage | Remove-AppxPackage -Confirm:$false

2015-03-13_14h52_51    2015-03-13_15h24_13    2015-03-13_15h24_54

2015-03-13_15h25_13    2015-03-13_15h26_15    2015-03-13_15h26_25

2015-03-13_15h27_21    2015-03-13_15h27_27

Microsoft Virtual Machine Converter 2.0

Screen-Shot-2014-04-08-at-22.10.53

Microsoft® Virtual Machine Converter (MVMC) is a Microsoft-supported, stand-alone solution for the information technology (IT) pro or solution provider who wants to convert virtual machines and disks from VMware hosts to Hyper-V® hosts and Windows Azure™.

MVMC can be deployed with minimal dependencies. Because MVMC provides native support for Windows PowerShell®, it enables scripting and integration with data center automation workflows such as those authored and run within Microsoft System Center Orchestrator 2012 R2. It can also be invoked through the Windows PowerShell® command-line interface. The solution is simple to download, install, and use. In addition to the Windows PowerShell capability, MVMC provides a wizard-driven GUI to facilitate virtual machine conversion.

New Features in MVMC 2.0
MVMC 2.0 release of MVMC includes the following new features:
◾Converts virtual disks that are attached to a VMware virtual machine to virtual hard disks (VHDs) that can be uploaded to Windows Azure.
◾Provides native Windows PowerShell capability that enables scripting and integration into IT automation workflows.
Note The command-line interface (CLI) in MVMC 1.0 has been replaced by Windows PowerShell in MVMC 2.0.
◾Supports conversion and provisioning of Linux-based guest operating systems from VMware hosts to Hyper-V hosts. ◾Supports conversion of offline virtual machines.
◾Supports the new virtual hard disk format (VHDX) when converting and provisioning in Hyper-V in Windows Server® 2012 R2 and Windows Server 2012.
◾Supports conversion of virtual machines from VMware vSphere 5.5, VMware vSphere 5.1, and VMware vSphere 4.1 hosts Hyper-V virtual machines.
◾Supports Windows Server® 2012 R2, Windows Server® 2012, and Windows® 8 as guest operating systems that you can select for conversion.

Standard MVMC Features  
In addition to the new features previously identified, MVMC provides the following functionality:
◾Converts and deploys virtual machines from VMware hosts to Hyper-V hosts on any of the following operating systems: ◾Windows Server® 2012 R2
◾Windows Server® 2012
◾Windows Server 2008 R2 SP1
◾Converts VMware virtual machines, virtual disks, and configurations for memory, virtual processor, and other virtual computing resources from the source to Hyper-V.
◾Adds virtual network interface cards (NICs) to the converted virtual machine on Hyper-V.
◾Supports conversion of virtual machines from VMware vSphere 5.5, VMware vSphere 5.0, and VMware vSphere 4.1 hosts to Hyper-V.
◾Has a wizard-driven GUI, which simplifies performing virtual machine conversions.
◾Uninstalls VMware Tools before online conversion (online only) to provide a clean way to migrate VMware-based virtual machines to Hyper-V.
Important  MVMC takes a snapshot of the virtual machine that you are converting before you uninstall VMware Tools, and then shuts down the source machine to preserve state during conversion. The virtual machine is restored to its previous state after the source disks that are attached to the virtual machine are successfully copied to the machine where the conversion process is run. At that point, the source machine in VMware can be turned on, if required. Important  MVMC does not uninstall VMware Tools in an offline conversion. Instead, it disables VMware services, drivers, and programs only for Windows Server guest operating systems. For file conversions with Linux guest operating systems, VMware Tools are not disabled or uninstalled. We highly recommend that you manually uninstall VMware Tools when you convert an offline virtual machine.
◾Supports Windows Server and Linux guest operating system conversion. For more details, see the section “Supported Configurations for Virtual Machine Conversion” in this guide.
◾Includes Windows PowerShell capability for offline conversions of VMware-based virtual hard disks (VMDK) to a Hyper-V–based virtual hard disk file format (.vhd file).  Note The offline disk conversion does not include driver fixes.

You can download Microsoft Virtual Machine Converter 2.0 here

How to: Create a VM within a few second in Hyper-V 2012 R2

In some cases I’ve to create multiple VM’s within my Hyper-V environment. You can choose to create and configure each VM manually, but you can also use PowerShell. Now you can see how powerfull PowerShell really is! I’ve created multiple VM’s within a few seconds and ready to rock! I’ve created the following script. The only thing you’ve to do, is changing some variables 🙂

In this example the script will create a new VM named RES-MGN01. The VM will be configured with 2 GB, using Dynamic Memory. The VM is using a differencing disk (VHDK) with a Windows Server 2012 R2 sysprepped parent VHDX, placed on an SSD disk (P: drive) in my server. The virtual switch the VM is connected to, is named NIC – WAN.

$VMName = “RES-MGN01”
$VMMemMaxBytes = 2048MB
$VHDXName = “OS.vhdx”
$VMMemStartup = 512MB
$VMMemMinBytes = 512MB
$VMPath = “E:\”
$VHDParent = “P:\Hyper-V Parents\TMPL-W2012R2DC\Virtual Hard Disks\TMPL-W2012R2DC.vhdx”
$VMSwitchName = “NIC – WAN”

New-VM -Name $VMName -Path $VMpath$VMName -Generation 2 -SwitchName $VMSwitchName

Set-VM -Name $VMName -DynamicMemory -MemoryStartupBytes 512MB -MemoryMinimumBytes $VMMemMinBytes -MemoryMaximumBytes $VMMemMaxBytes

New-VHD -ParentPath $VHDParent -Path $VMPath\$VMName\$VMName\$VHDXName -Differencing

Add-VMHardDiskDrive -VMName $VMName -Path $VMPath\$VMName\$VMName\$VHDXName

Add-VMDvdDrive -VMName $VMName

Start-VM -Name $VMName

2014-01-14_11h48_41    2014-01-14_11h49_20    2014-01-14_11h50_27

2014-01-14_11h51_18    2014-01-14_11h52_12