Hyper-V VM Scripts

<#

ImportHyperVVM.ps1

Dries Willems

03/12/2014

#>

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V –All -NoRestart

Restart-Computer -Wait -For PowerShell -Timeout 600 -Delay 2

Import-Module Hyper-V

$ethernet = Get-NetAdapter -Name ethernet

$wifi = Get-NetAdapter -Name wi-fi

New-VMSwitch -Name EthernetExternalSwitch -NetAdapterName $ethernet.Name -AllowManagementOS $true -Notes ‘Parent OS, VMs, LAN’

New-VMSwitch -Name WiFiExternalSwitch -NetAdapterName $wifi.Name -AllowManagementOS $true -Notes ‘Parent OS, VMs, wifi’

Copy-Item * C:\VM

Import-VM -Path ‘C:\VM\Cobra\Virtual Machines\6FAEE0C5-7422-45BD-A915-AA3C3A5D06A7.XML’

$OldHostname = Get-WmiObject win32_computersystem | select-object -expandproperty name

$NewHostname = $OldHostname + “VM”

Rename-VM Cobra $NewHostname

Start-VM $NewHostname

———————————————————————————————

<#

RenameStartVM.ps1

Dries Willems

03/12/2014

#>

$OldHostname = Get-WmiObject win32_computersystem | select-object -expandproperty name

$NewHostname = $OldHostname + “VM”

Rename-VM Cobra $NewHostname

Start-VM $NewHostname

———————————————————————————————

<#

CreateVSwitchImportRenameStartCobra.ps1

Dries Willems

03/12/2014

#>

Import-Module Hyper-V

#Create Virtual Switch

$ethernet = Get-NetAdapter -Name ethernet

$wifi = Get-NetAdapter -Name wi-fi

New-VMSwitch -Name EthernetExternalSwitch -NetAdapterName $ethernet.Name -AllowManagementOS $true -Notes ‘Parent OS, VMs, LAN’

New-VMSwitch -Name WiFiExternalSwitch -NetAdapterName $wifi.Name -AllowManagementOS $true -Notes ‘Parent OS, VMs, wifi’

#Import VM

Import-VM -Path ‘C:\VM\Cobra\Virtual Machines\8F300942-505B-41C0-8644-B46321581214.XML’

#Rename VM & Start

$OldHostname = Get-WmiObject win32_computersystem | select-object -expandproperty name

$NewHostname = $OldHostname + “VM”

Rename-VM Cobra $NewHostname

Start-VM $NewHostname

——————————————————————————————–Cobra.bat

Powershell.exe -executionpolicy bypass -File .\CreateVSwitchImportRenameStartCobra.ps1

xcopy “C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Hyper-V Management Tools\VMConnect.lnk” “C:\Users\Public\Desktop\Hyper-V Virtual Machine Connection.lnk”* /I /S /Y /C /R


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *