Sunday 28 August 2016

Essential PowerShell Cmdlets For Managing Hyper-V

Installing Hyper-V

Get-WindowsFeature Hyper-V

Get-WindowsOptionalFeature -FeatureName "Microsoft-Hyper-V" -Online | Format-Table

Install-WindowsFeature Hyper-V -Restart

To enable Hyper-V on Windows 10, use the following script:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

Add-WindowsFeature RSAT-Hyper-V-Tools -IncludeAllSubFeature

Creating Virtual Machine Resources

New-item -itemType directory -Path ("C:\VM", C:\VM\iso") -Force


Creatign Virtual Switch

get-netadapter

New-VMSwitch -Name VMSwitch -NetAdapterName Ethernet
New-VMSwitch -Name VMSwitchInternal -SwitchType Private

Creating Virtual Hard Disk as a fixed size vhdx file
New-VHD -Path C:\VM\VH01.vhdx -Fixed -SizeBytes 10gb

Creating VMs
New-VM -Name "Ubuntu Desktop" -VHDPath .\UbuntuDesktop1.vhdx -MemoryStartupBytes 1024mb

New-VM -Name "Ubuntu Desktop Dynamic Disk" -NewVHDPath .\DynamicDisk.vhdx -NewVHDSizeBytes 10gb -MemoryStartupBytes 1024mb

Add-VMDvdDrive -VMName "Ubuntu Desktop" -Path .\iso\Ubuntu-16.04-desktop-amd64.iso




How to change between a Full Installation (GUI) and Server Core in Windows Server 2012

Adding the GUI to a Server Core Installation
===========================

Install-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra

Restart the server, once installed with the following command.

Restart-Computer
The installation will hang at 68% and after a while display an error message:
Install-WindowsFeature: The request to add or remove features on the specified server failed.

Follow these steps to solve this:

mkdir c:\mount

dism /get-wiminfo /wimfile:d:\sources\install.wim

Mount the WIM file

dism /mount-wim /wimfile: d:\sources\install.wim /index:4 /mountdir:c:\Mount\ /readonly

Install and specify the source:
Install-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra -Source C:\Mount\Windows\WinSXS
 
Restart the server, once installed.
 
Restart-Computer
 
 
 
Removing the GUI from a full installation, using Powershell:
Uninstall-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra
 
 
 
 
Ref:
http://www.danielclasson.com/how-to-change-between-a-full-installation-gui-and-server-core-in-windows-server-2012/
http://blog.coretech.dk/kaj/why-i-cant-convert-my-windows-server-2012-r2-core-to-gui/
How to change between a Full Installation (GUI) and Server Core in Windows Server 2012

Adding the GUI to a Server Core Installation
===========================

Install-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra

Restart the server, once installed with the following command.

Restart-Computer
The installation will hang at 68% and after a while display an error message:
Install-WindowsFeature: The request to add or remove features on the specified server failed.

Follow these steps to solve this:

mkdir c:\mount

dism /get-wiminfo /wimfile:d:\sources\install.wim

Mount the WIM file

dism /mount-wim /wimfile: d:\sources\install.wim /index:4 /mountdir:c:\Mount\ /readonly

Install and specify the source:
Install-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra -Source C:\Mount\Windows\WinSXS
 
Restart the server, once installed.
 
Restart-Computer
 
 
 
Removing the GUI from a full installation, using Powershell:
Uninstall-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra
 
 
 
 
Ref:
http://www.danielclasson.com/how-to-change-between-a-full-installation-gui-and-server-core-in-windows-server-2012/
http://blog.coretech.dk/kaj/why-i-cant-convert-my-windows-server-2012-r2-core-to-gui/