Skip to content

Instantly share code, notes, and snippets.

@techthoughts2
Created October 6, 2015 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techthoughts2/2c1cf121691d1ccbdc2a to your computer and use it in GitHub Desktop.
Save techthoughts2/2c1cf121691d1ccbdc2a to your computer and use it in GitHub Desktop.
Various Hyper-V Related PowerShell
#------------------------------------------------------
#check currently installed roles
Get-WindowsFeature | where {$_.installed -eq "True"}
#------------------------------------------------------
#------------------------------------------------------
#install the Hyper-V Role
Install-WindowsFeature Hyper-V -IncludeManagementTools -Restart -Verbose
#------------------------------------------------------
#----------------NIC TEAMING----------------------------
# This will loop through and get all available NICs and add them to the team
$NICname = Get-NetAdapter | %{$_.name}
# New Network Team
New-NetLbfoTeam -Name PublicNetTeam –TeamMembers $NICname -TeamingMode SwitchIndependent -LoadBalancingAlgorithm HyperVPort -Confirm:$false
Start-Sleep -s 15
$netadapter = Get-NetAdapter -Name PublicNetTeam;
$netadapter | Set-NetIPInterface -DHCP Disabled;
#we will now set the IP, gateway, and DNS of the new PublicNetTeam
$Script:primaryIP = "10.0.3.50"
$Script:pNetMask = "24"
$Script:pgateway = "10.0.3.1"
$Script:dns1 = "10.0.3.189"
$Script:dns2 = "10.0.3.1"
$netadapter | New-NetIPAddress -AddressFamily IPv4 -IPAddress $Script:primaryIP -PrefixLength $Script:pNetMask -Type Unicast -DefaultGateway $Script:pgateway | Out-Null;
Set-DnsClientServerAddress -InterfaceAlias PublicNetTeam -ServerAddresses $Script:dns1,$Script:dns2 | Out-Null
#---------------END NIC TEAMING-------------------------
#------------------------------------------------------
#create new virtual switch
New-VMSwitch -NetAdapterName PublicNetTeam -Name "PublicVSwitch" -AllowManagementOS $true -Confirm:$false
#------------------------------------------------------
#------------------------------------------------------
#Set Default HYPER-V locations
SET-VMHost -virtualharddiskpath V:\VHDs
Set-VMHost -virtualmachinepath V:\VMs
#------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment