달력

9

« 2013/9 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
#####################################
 $ClusterName = "<Hyper-V 클러스터 이름>"
 $DPMServerName = "<DPM 서버 이름>"

 $PGPrefix = "<보호 그룹 접두어>"
 $VMPrefix = "<VM 이름 접두어>"
#####################################

If ($DPMServerName -notlike "*.$env:userdnsdomain")
{
  $DPMFQDN = $DPMServerName+".$env:userdnsdomain"
}
Else
{
  $DPMFQDN = $DPMServerName
}

Connect-DPMServer $DPMFQDN

$Cluster = Get-DPMProductionCluster $DPMFQDN | Where {$_.ClusterName -like "$ClusterName.*"}
$NotProtectedVM = Get-DPMProductionVirtualName $Cluster | Where {$_.MachineName -like "SCVMM*$VMPrefix*" -and $_.ServerProtectionState -ne "HasDatasourcesProtected"}

# 초기 복제 시간 설정 (밤 12시)
$tmpDate = Get-Date
$tmpDate = [String]$tmpDate.Year+"-"+[String]$tmpDate.Month+"-"+[String]$tmpDate.Day
$tmpDate = [DateTime]$tmpDate
$ReplicaCreationTime = [DateTime]$tmpDate.AddDays(1)

# 백업되고 있지 않은 VM을 보호 그룹에 추가
# 보호 그룹은 구성원 수가 가장 적은 그룹 선택
foreach ($Item in $NotProtectedVM)
{
  $TargetDS = $Item | Get-DPMDatasource -Inquire | Where {$_.ObjectType -like "*Hyper-V*"}
  If (! $TargetDS) {continue}
  Else
  {
    $TargetPG = Get-DPMProtectionGroup $DPMFQDN | Where {$_.Name -like "$PGPrefix*"} | Sort-Object -Property NumberOfShortTermDatasources,TotalDiskReplicaSize | Select-Object -First 1
    $MPG = Get-DPMModifiableProtectionGroup $TargetPG
    $NPG = Add-DPMChildDatasource -ProtectionGroup $MPG -ChildDatasource $TargetDS
    $DiskAlloc = Get-DatasourceDiskAllocation -Datasource $TargetDS
    Set-DatasourceDiskAllocation -Datasource $TargetDS -ProtectionGroup $MPG
    Set-DPMReplicaCreationMethod -ProtectionGroup $MPG -Later $ReplicaCreationTime
    Set-DPMProtectionGroup $MPG
  }
}


 
:
Posted by 커널64
Windows Server 2012 기반의 Hyper-V 인프라 구성 시 필요한 몇 가지 구성들을 '빼먹지 않고', 좀 더 '손 쉽게' 할 수 있도록 PowerShell 스크립트로 만들어 보았습니다. 기본적인 권장 구성과 역할 및 기능 설치, 네트워크 관련 설정들이 포함됩니다.






Function Essential
{
  Clear-Host
  Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 2"
  Write-Host `n"------------------------------------"
  Write-Host "-- Essential Settings for Hyper-V --"
  Write-Host "------------------------------------"`n
  Write-Host "Checking Current Status ..."`n

  Write-Host -NoNewline " - TCP Chimney Offload: "
  $NetGlobalSettings = Get-NetOffloadGlobalSetting
  If ($NetGlobalSettings.Chimney -eq "Enabled") {Write-Host -foregroundColor Red "Enabled"}
  Else {Write-Host -foregroundColor Green "Disabled"}

  Write-Host -NoNewline " - User Access Control: "
  $LUA = Get-ItemProperty "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
  If ($LUA.EnableLUA -ne "0") {Write-Host -foregroundColor Red "Enabled"}
  Else {Write-Host -foregroundColor Green "Disabled"}

  Write-Host -NoNewline " - IP Version 6 (IPv6): "
  $IPv6 = Get-ItemProperty "HKLM:SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters"
  If ($IPv6.DisabledComponents -ne "4294967295") {Write-Host -foregroundColor Red "Enabled"}
  Else {Write-Host -foregroundColor Green "Disabled"}

  Write-Host -NoNewline " - Remote Desktop Connection: "
  $RDP = Get-ItemProperty "HKLM:SYSTEM\CurrentControlSet\Control\Terminal Server"
  If ($RDP.fDenyTSConnections -ne "0") {Write-Host -foregroundColor Red "Disabled"}
  Else {Write-Host -foregroundColor Green "Enabled"}

  Write-Host -NoNewline " - Remote Desktop Network Level Authentication: "
  $RDPSet = Get-ItemProperty "HKLM:SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp"
  If ($RDPSet.UserAuthentication -ne "0") {Write-Host -foregroundColor Red "Enabled"}
  Else {Write-Host -foregroundColor Green "Disabled"}

  Write-Host -NoNewline " - Remote Server Management: "
  $RemoteMgmt = Invoke-Expression -Command "Configure-SMRemoting.exe -GET"
  If ($RemoteMgmt -like "*사용하지 않도록*") {Write-Host -foregroundColor Red "Disabled"}
  Else {Write-Host -foregroundColor Green "Enabled"}

  Write-Host -NoNewline " - Firewall Exception(Remote Desktop Connection): "
  $FWRules = Get-NetFirewallRule | Where {$_.Group -eq "@FirewallAPI.dll,-28752"}
  $FWState = 0
  foreach ($Item in $FWRules)
  {
    If ($Item.Enabled -eq "False") {$FWState = 1}
  }
  If ($FWState -eq 1) {Write-Host -foregroundColor Red "Disabled"}
  Else {Write-Host -foregroundColor Green "Enabled"}

  Write-Host -NoNewline " - Firewall Exception(File and Printer Sharing): "
  $FWRules = Get-NetFirewallRule | Where {$_.Group -eq "@FirewallAPI.dll,-28502"}
  $FWState = 0
  foreach ($Item in $FWRules)
  {
    If ($Item.Enabled -eq "False") {$FWState = 1}
  }
  If ($FWState -eq 1) {Write-Host -foregroundColor Red "Disabled"}
  Else {Write-Host -foregroundColor Green "Enabled"}

  Write-Host -NoNewline " - Firewall Exception(Windows Remote Management): "
  $FWRules = Get-NetFirewallRule | Where {$_.Group -eq "@FirewallAPI.dll,-30267"}
  $FWState = 0
  foreach ($Item in $FWRules)
  {
    If ($Item.Enabled -eq "False") {$FWState = 1}
  }
  If ($FWState -eq 1) {Write-Host -foregroundColor Red "Disabled"}
  Else {Write-Host -foregroundColor Green "Enabled"}

  Write-Host -NoNewline " - Firewall Exception(Remote Service Management): "
  $FWRules = Get-NetFirewallRule | Where {$_.Group -eq "@FirewallAPI.dll,-29502"}
  $FWState = 0
  foreach ($Item in $FWRules)
  {
    If ($Item.Enabled -eq "False") {$FWState = 1}
  }
  If ($FWState -eq 1) {Write-Host -foregroundColor Red "Disabled"}
  Else {Write-Host -foregroundColor Green "Enabled"}
  
  Write-Host -NoNewline " - Firewall Exception(COM+ Remote Management): "
  $FWRules = Get-NetFirewallRule | Where {$_.Group -eq "@comres.dll,-3405"}
  $FWState = 0
  foreach ($Item in $FWRules)
  {
    If ($Item.Enabled -eq "False") {$FWState = 1}
  }
  If ($FWState -eq 1) {Write-Host -foregroundColor Red "Disabled"}
  Else {Write-Host -foregroundColor Green "Enabled"}

  Write-Host -NoNewline " - Firewall Exception(Remote Event Log Management): "
  $FWRules = Get-NetFirewallRule | Where {$_.Group -eq "@FirewallAPI.dll,-29252"}
  $FWState = 0
  foreach ($Item in $FWRules)
  {
    If ($Item.Enabled -eq "False") {$FWState = 1}
  }
  If ($FWState -eq 1) {Write-Host -foregroundColor Red "Disabled"}
  Else {Write-Host -foregroundColor Green "Enabled"}

  Write-Host -NoNewline " - Firewall Exception(WMI(Windows Management Instrumentation)): "
  $FWRules = Get-NetFirewallRule | Where {$_.Group -eq "@FirewallAPI.dll,-34251"}
  $FWState = 0
  foreach ($Item in $FWRules)
  {
    If ($Item.Enabled -eq "False") {$FWState = 1}
  }
  If ($FWState -eq 1) {Write-Host -foregroundColor Red "Disabled"}
  Else {Write-Host -foregroundColor Green "Enabled"}

  Write-Host -NoNewline " - Disallow Client Printer Redirection: "
  $PrinterMap = Get-ItemProperty "HKLM:SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services"
  If ($PrinterMap.fDisableCpm -ne "1" -or $PrinterMap.fDisableCpm -eq $NULL) {Write-Host -foregroundColor Red "Disabled"`n}
  Else {Write-Host -foregroundColor Green "Enabled"`n}

  Do
  {
    Write-Host -NoNewline `n"Set All to Desired Configurations? "
    Write-Host -foregroundColor Yellow -NoNewline "[Y]"
    Write-Host -NoNewline " or "
    Write-Host -foregroundColor Yellow -NoNewline "[N]"
    Write-Host -NoNewline ": "
    $DesiredConfig = Read-Host
  }
  While ($DesiredConfig -ne "Y" -and $DesiredConfig -ne "N")

  Switch ($DesiredConfig)
  {
    "Y"
    {
      Clear-Host
      Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 3"

      Write-Host `n`n"Disable TCP Chimney Offload"
      Set-NetOffloadGlobalSetting -Chimney Disabled
      Write-Host " -> Completed!"

      Write-Host `n"Turn Off User Access Control"
      Set-ItemProperty "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name EnableLUA -Value 0
      Write-Host " -> Completed!"

      Write-Host `n"Disable IP Version 6 (IPv6)"
      Set-ItemProperty "HKLM:SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters" -Name DisabledComponents -Value 4294967295
      Write-Host " -> Completed!"

      Write-Host `n"Enable Remote Desktop Connection"
      Set-ItemProperty "HKLM:SYSTEM\CurrentControlSet\Control\Terminal Server" -Name fDenyTSConnections -Value 0
      Write-Host " -> Completed!"

      Write-Host `n"Disable Remote Desktop Network Level Authentication"
      Set-ItemProperty "HKLM:SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" -Name UserAuthentication -Value 0
      Write-Host " -> Completed!"

      Write-Host `n"Enable Remote Server Management"
      $RemoteMgmt = Invoke-Expression -Command "Configure-SMRemoting.exe -Enable"
      $CommandLineStr = "winrm set winrm/config/client '@{TrustedHosts="+$([Char]34)+"*"+$([Char]34)+"}'"
      $RemoteMgmt = Invoke-Expression -Command $CommandLineStr
      Write-Host " -> Completed!"

      Write-Host `n"Configure Firewall Exceptions"
      $TargetFWRules = Get-NetFirewallRule | Where {$_.Group -eq "@FirewallAPI.dll,-28752" -or $_.Group -eq "@FirewallAPI.dll,-28502" -or $_.Group -eq "@FirewallAPI.dll,-30267" -or $_.Group -eq "@FirewallAPI.dll,-29502" -or $_.Group -eq "@comres.dll,-3405" -or $_.Group -eq "@FirewallAPI.dll,-29252" -or $_.Group -eq "@FirewallAPI.dll,-34251" -or $_.Group -eq "@FirewallAPI.dll,-29002"}
      $TargetFWRules | Set-NetFirewallRule -Enabled True
      Write-Host " -> Completed!"

      Write-Host `n"Disallow Client Printer Redirection"
      Set-ItemProperty "HKLM:SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services" -Name fDisableCpm -Value 1
      Write-Host " -> Completed!"

      Write-Host `n`n"Press Any Key to Continue..."
      $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
    }

    "N"
    {
      Write-Host `n"Canceled."
      Start-Sleep 1
      Break
    }
  }
}


Function WindowsFeatures
{
  Clear-Host
  Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 2"
  Write-Host `n"----------------------------------------------------------"
  Write-Host "-- Windows Features for Hyper-V and Failover Clustering --"
  Write-Host "----------------------------------------------------------"`n
  Write-Host "Checking Current Status ..."`n

  $WinFeatures = Get-WindowsFeature -Name Hyper-V, Failover-Clustering, Multipath-IO, Telnet-Client

  Write-Host -NoNewline " - Hyper-V Role: "
  $HV = $WinFeatures | Where {$_.Name -eq "Hyper-V"}
  If ($HV.Installed -ne "True") {Write-Host -foregroundColor Red "Not Installed"}
  Else {Write-Host -foregroundColor Green "Installed"}

  Write-Host -NoNewline " - Failover Clustering: "
  $WSFC = $WinFeatures | Where {$_.Name -eq "Failover-Clustering"}
  If ($WSFC.Installed -ne "True") {Write-Host -foregroundColor Red "Not Installed"}
  Else {Write-Host -foregroundColor Green "Installed"}

  Write-Host -NoNewline " - Multipath IO: "
  $MPIO = $WinFeatures | Where {$_.Name -eq "Multipath-IO"}
  If ($MPIO.Installed -ne "True") {Write-Host -foregroundColor Red "Not Installed"}
  Else {Write-Host -foregroundColor Green "Installed"}

  Write-Host -NoNewline " - Telnet Client: "
  $TC = $WinFeatures | Where {$_.Name -eq "Telnet-Client"}
  If ($TC.Installed -ne "True") {Write-Host -foregroundColor Red "Not Installed"`n}
  Else {Write-Host -foregroundColor Green "Installed"`n}

  Do
  {
    Write-Host -NoNewline `n"Install All Required Windows Features? "
    Write-Host -foregroundColor Yellow -NoNewline "[Y]"
    Write-Host -NoNewline " or "
    Write-Host -foregroundColor Yellow -NoNewline "[N]"
    Write-Host -NoNewline ": "
    $InstallWinFeatures = Read-Host
  }
  While ($InstallWinFeatures -ne "Y" -and $InstallWinFeatures -ne "N")

  Switch ($InstallWinFeatures)
  {
    "Y"
    {
      Add-WindowsFeature Telnet-Client,Failover-Clustering,Multipath-IO,Hyper-V -IncludeManagementTools -Verbose
      Write-Host `n`n`n"Completed. System would be required Reboot."
      Write-Host `n"Press Any Key to Continue..."
      $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
    }

    "N"
    {
      Write-Host `n"Canceled."
      Start-Sleep 1
    }
  }
}


Function VirtualNetworks
{
  Do
  {
    Clear-Host
    Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 2"
    Write-Host `n"-------------------------------------------------"
    Write-Host "-- Physical and Virtual Network Configurations --"
    Write-Host "-------------------------------------------------"
    Write-Host `n"1) Rename Network Interfaces"
    Write-Host `n"2) Manage Virtual Switches and Interfaces"
    Write-Host `n"3) Configure IP Addresses (IPv4)"`n

    Do
    {
      Write-Host -NoNewline `n"Select Task "
      Write-Host -foregroundColor Yellow -NoNewline "[ID]"
      Write-Host -NoNewline " or "
      Write-Host -foregroundColor Yellow -NoNewline "[Q]"
      Write-Host -NoNewline "uit: "
      $PnVNetworkConfig = Read-Host
    }
    While ((!$PnVNetworkConfig -or $PnVNetworkConfig -eq 0) -and $PnVNetworkConfig -ne "Q")

    If ($PnVNetworkConfig -eq "Q") {Break}
    
    Switch ($PnVNetworkConfig)
    {
      "1"
      {
        Do
        {
          Clear-Host
          Write-Host `n`n"Retrieving Data. Please Wait..."

          $idx = 0
          $tmpArr = @()
          $NICs = Get-NetAdapter | Sort-Object -Property Name
          $IPs = Get-NetIPAddress | Where {$_.AddressFamily -eq "IPv4"}

          foreach ($Item in $NICs)
          {
            $idx++
            $idxStr = [String]$idx+")"
            $IfName = $Item.Name
            $IfDesc = $Item.InterfaceDescription
            $Speed = $Item.LinkSpeed
            $Status = $Item.Status
            $IPAddress = ""
            $IfIPConfig = Get-NetIPInterface | Where {$_.InterfaceAlias -eq $IfName}

            If ($IfIPConfig.Dhcp -eq "Enabled") {$IPAddress = "DHCP"}
            ElseIf (! $IfIPConfig) {$IPAddress = "N/A"}
            Else
            {
              foreach ($Item1 in $IPs)
              {
                If ($Item1.InterfaceIndex -eq $Item.InterfaceIndex) {$IPAddress = $Item1.IPAddress+"/"+$Item1.PrefixLength}
              }
            }

            $Output = New-Object PSObject
            $Output | Add-Member Noteproperty Index $idxStr
            $Output | Add-Member Noteproperty Name $IfName
            $Output | Add-Member Noteproperty Description $IfDesc
            $Output | Add-Member Noteproperty "IP Address" $IPAddress
            $Output | Add-Member Noteproperty Speed $Speed
            $Output | Add-Member Noteproperty Status $Status
            $tmpArr += $Output
          }

          Clear-Host
          Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 3"
          Write-Host `n"-------------------------------"
          Write-Host "-- Rename Network Interfaces --"
          Write-Host "-------------------------------"
          $tmpArr | ft -AutoSize

          Do
          {
            Write-Host -NoNewline `n"Select Interface "
            Write-Host -foregroundColor Yellow -NoNewline "[ID]"
            Write-Host -NoNewline " or "
            Write-Host -foregroundColor Yellow -NoNewline "[Q]"
            Write-Host -NoNewline "uit: "
            $RenameNIC = Read-Host
          }
          While ((!$RenameNIC -or $RenameNIC -eq 0) -and $RenameNIC -ne "Q")

          If ($RenameNIC -eq "Q") {Break}

          $RenameNIC = [Int]$RenameNIC-1
          $NewName = Read-Host `n`n"New Name for the Network Interface (Blank: Cancel)"
          If (! $NewName) {Write-Host `n"Canceled."}
          Else
          {
            $NICs[$RenameNIC] | Rename-NetAdapter -NewName $NewName
            Write-Host `n"Done."
          }
          Start-Sleep 1
        }
        While ($True)
      }

      "2"
      {
        Do
        {
          Clear-Host
          Write-Host `n`n"Retrieving Data. Please Wait..."

          $idx = 0
          $tmpArr = @()
          $NICs = Get-NetAdapter
          $VSW = Get-VMSwitch

          If (! $VSW) {Write-Host `n`n"There is no Virtual Switch."`n`n}
          Else
          {
            foreach ($Item in $VSW)
            {
              $idx++
              $idxStr = [String]$idx+")"
              $UpNIC = $NICs | Where {$_.InterfaceDescription -eq $Item.NetAdapterInterfaceDescription}
              $Output = New-Object PSObject
              $Output | Add-Member Noteproperty Index $idxStr
              $Output | Add-Member Noteproperty "Switch Name" $Item.Name
              $Output | Add-Member Noteproperty "Switch Type" $Item.SwitchType
              $Output | Add-Member Noteproperty "QoS Mode" $Item.BandwidthReservationMode
              $Output | Add-Member Noteproperty "QoS Default Weight" $Item.DefaultFlowMinimumBandwidthWeight
              $Output | Add-Member Noteproperty "Default Bandwidth %" $Item.BandwidthPercentage
              $Output | Add-Member Noteproperty "NIC Name" $UpNIC.Name
              $Output | Add-Member Noteproperty "NIC Description" $UpNIC.InterfaceDescription
              $Output | Add-Member Noteproperty "NIC Speed" $UpNIC.LinkSpeed
              $Output | Add-Member Noteproperty "NIC Status" $UpNIC.Status
              $tmpArr += $Output
            }

            Clear-Host
            Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 3"
            Write-Host `n"--------------------------------------------"
            Write-Host "-- Manage Virtual Switches and Interfaces --"
            Write-Host "--------------------------------------------"
            $tmpArr | ft Index,"Switch Name","Switch Type","NIC Name","NIC Description","NIC Speed","NIC Status" -AutoSize

            Do
            {
              Write-Host -NoNewline `n"Select Virtual Switch "
              Write-Host -foregroundColor Yellow -NoNewline "[ID]"
              Write-Host -NoNewline ", Create "
              Write-Host -foregroundColor Yellow -NoNewline "[N]"
              Write-Host -NoNewline "ew Virtual Switch or "
              Write-Host -foregroundColor Yellow -NoNewline "[Q]"
              Write-Host -NoNewline "uit: "
              $ManageVSWnIf = Read-Host
            }
            While ((!$ManageVSWnIf -or $ManageVSWnIf -eq 0) -and $ManageVSWnIf -ne "N" -and $ManageVSWnIf -ne "Q")
            If ($ManageVSWnIf -eq "Q") {Break}

            If ($ManageVSWnIf -eq "N")
            {
              Do
              {
                Clear-Host
                Write-Host `n`n"Searching for Available Network Interfaces. Please Wait..."

                $idx = 0
                $tmpArr = @()
                $IPs = Get-NetIPAddress | Where {$_.AddressFamily -eq "IPv4"}
                $HostNIC = Get-VMNetworkAdapter -ManagementOS
                $NICs = Get-NetAdapterBinding | Where {$_.ComponentID -eq "ms_tcpip" -and $_.Enabled -eq "True"} | Get-NetAdapter | Sort-Object -Property Name

                foreach ($Item in $NICs)
                {
                  $isAvail = 1
                  foreach ($Item1 in $HostNIC)
                  {
                    $tmpMAC = $Item.MacAddress.Replace("-","")
                    If ($tmpMAC -eq $Item1.MacAddress) {$isAvail = 0}
                  }

                  If ($isAvail -eq 1)
                  {
                    $idx++
                    $idxStr = [String]$idx+")"
                    $IPAddress = ""
                    foreach ($Item3 in $IPs)
                    {
                      If ($Item3.InterfaceIndex -eq $Item.InterfaceIndex) {$IPAddress = $Item3.IPAddress+"/"+$Item3.PrefixLength}
                    }
                    $Output = New-Object PSObject
                    $Output | Add-Member Noteproperty Index $idxStr
                    $Output | Add-Member Noteproperty Name $Item.Name
                    $Output | Add-Member Noteproperty Description $Item.InterfaceDescription
                    $Output | Add-Member Noteproperty "IP Address" $IPAddress
                    $Output | Add-Member Noteproperty Speed $Item.LinkSpeed
                    $Output | Add-Member Noteproperty Status $Item.Status
                    $tmpArr += $Output
                  }
                }

                Clear-Host
                Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 4"
                Write-Host `n"-------------------------------"
                Write-Host "-- Create New Virtual Switch --"
                Write-Host "-------------------------------"

                $tmpArr | ft -AutoSize

                Do
                {
                  Write-Host -NoNewline `n"Select Interface "
                  Write-Host -foregroundColor Yellow -NoNewline "[ID]"
                  Write-Host -NoNewline " or "
                  Write-Host -foregroundColor Yellow -NoNewline "[Q]"
                  Write-Host -NoNewline "uit: "
                  $CreateVSW = Read-Host
                }
                While ((!$CreateVSW -or $CreateVSW -eq 0) -and $CreateVSW -ne "Q")
                
                If ($CreateVSW -eq "Q") {Break}

                $CreateVSW = [Int]$CreateVSW-1
                $NICName = $tmpArr[$CreateVSW].Name

                $VSWName = Read-Host `n"New Virtual Switch Name (Blank: Cancel)"
                If (! $VSWName)
                {
                  Write-Host `n"Canceled."
                  Start-Sleep 1
                  Break
                }

                Write-Host `n"Creating a New Virtual Switch. Please Wait..."
                $CreateVWS = New-VMSwitch -Name $VSWName -NetAdapterName $NICName -AllowManagementOS $False -MinimumBandwidthMode Weight
                $SetVSWBW = $CreateVWS | Set-VMSwitch -DefaultFlowMinimumBandwidthWeight 10
                $CreateVWS = Get-VMSwitch -Name $VSWName
                $CreateVWS | fl *
                Write-Host `n"Creation Succeeded."
                Write-Host `n"Press Any Key to Continue..."
                $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
                Break
              }
              While ($True)
            }

            If ($ManageVSWnIf -ne "N" -and $ManageVSWnIf -ne "Q")
            {
              $ManageVSWnIf = [Int]$ManageVSWnIf-1
              $VSWName = $tmpArr[$ManageVSWnIf]."Switch Name"

              Do
              {
                Clear-Host
                $SelectedVSW = Get-VMSwitch | Where {$_.Name -eq $VSWName}
                If (! $SelectedVSW) {Break}

                Write-Host `n`n"Retrieving Data. Please Wait..."
                $VSWType = $SelectedVSW.SwitchType
                $VSWQoSMode = $SelectedVSW.BandwidthReservationMode
                $VSWDefaultQoS = $SelectedVSW.DefaultFlowMinimumBandwidthWeight
                $VSWDefaultPerc = $SelectedVSW.BandwidthPercentage
                $VSWNICDesc = $SelectedVSW.NetAdapterInterfaceDescription

                $VSWNIC = Get-NetAdapter | Where {$_.InterfaceDescription -eq $VSWNICDesc}
                $VSWNICName = $VSWNIC.Name
                $VSWNICSpeed = $VSWNIC.LinkSpeed
                $VSWNICStatus = $VSWNIC.Status
                $vNIC = Get-VMNetworkAdapter -ManagementOS -SwitchName $VSWName -ErrorAction SilentlyContinue
                $VSWvNIC = $vNIC.Count

                Clear-Host
                Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 4"
                Write-Host `n"-----------------------------"
                Write-Host "-- Selected Virtual Switch --"
                Write-Host "-----------------------------"
                Write-Host `n" - Name: "$VSWName
                Write-Host `n" - Type: "$VSWType
                Write-Host `n" - QoS Mode: "$VSWQoSMode
                Write-Host `n" - QoS Default Weight: "$VSWDefaultQoS
                Write-Host `n" - Default Bandwidth: "$VSWDefaultPerc" %"
                Write-Host `n" - NIC Name: "$VSWNICName
                Write-Host `n" - NIC Description: "$VSWNICDesc
                Write-Host `n" - Link Speed: "$VSWNICSpeed
                Write-Host `n" - Link Status: "$VSWNICStatus
                Write-Host `n" - # of Management vNIC: "$VSWvNIC`n

                Do
                {
                  Write-Host -NoNewline `n"Re"
                  Write-Host -foregroundColor Yellow -NoNewline "[N]"
                  Write-Host -NoNewline "ame, "
                  Write-Host -foregroundColor Yellow -NoNewline "[R]"
                  Write-Host -NoNewline "emove, "
                  Write-Host -foregroundColor Yellow -NoNewline "[C]"
                  Write-Host -NoNewline "hange Default Weight or "
                  Write-Host -foregroundColor Yellow -NoNewline "[M]"
                  Write-Host -NoNewline "anage vNIC (Blank: Cancel): "
                  $VSWTask = Read-Host
                }
                While ($VSWTask -ne "N" -and $VSWTask -ne "R" -and $VSWTask -ne "M" -and $VSWTask -ne "C" -and $VSWTask -ne "")

                If ($VSWTask -eq "")
                {
                  Write-Host `n"Canceled."
                  Start-Sleep 1
                  Break
                }

                Switch ($VSWTask)
                {
                  "N"
                  {
                    $NewVSWName = Read-Host `n"New Virtual Switch Name"
                    If ($NewVSWName -ne "")
                    {
                      $SelectedVSW | Rename-VMSwitch -NewName $NewVSWName
                      $VSWName = $NewVSWName
                      Write-Host `n"Done."
                    }
                    Else
                    {
                      Write-Host `n"Nothing Changed."
                    }
                    Start-Sleep 1
                  }

                  "R"
                  {
                    Do
                    {
                      $VSWtoRemove = $SelectedVSW.Name
                      Write-Host -NoNewline `n"Removing Virtual Switch "
                      Write-Host -NoNewLine -foregroundColor Red $VSWtoRemove
                      Write-Host "."
                      Write-Host -NoNewLine "Are You Sure ? "
                      Write-Host -foregroundColor Yellow -NoNewline "[Y]"
                      Write-Host -NoNewline " or "
                      Write-Host -foregroundColor Yellow -NoNewline "[N]"
                      Write-Host -NoNewline ": "
                      $AUSure = Read-Host
                    }
                    While ($AUSure -ne "Y" -and $AUSure -ne "N")

                    If ($AUSure -eq "Y")
                    {
                      Write-Host `n`n"Removing Virtual Switch. Please Wait..."
                      $SelectedVSW | Remove-VMSwitch -Force
                      Write-Host `n"Done."
                      Start-Sleep 1
                      Break
                    }
                  }

                  "C"
                  {
                    $NewQoSValue = Read-Host `n"New Value of QoS Default Weight (1-100) (Blank: Cancel)"

                    If (! $NewQoSValue)
                    {
                      Write-Host `n"Canceled."
                      Start-Sleep 1
                    }
                    Else
                    {
                      $SelectedVSW | Set-VMSwitch -DefaultFlowMinimumBandwidthWeight $NewQoSValue
                      Write-Host `n"Done."
                      Start-Sleep 1
                    }
                  }

                  "M"
                  {
                    $SelSWName = $SelectedVSW.Name
                    Do
                    {
                      Clear-Host
                      Write-Host `n`n"Retrieving Data. Please Wait..."

                      $SelectedVSW = Get-VMSwitch | Where {$_.Name -eq $SelSWName}
                      If (! $SelectedVSW) {Break}

                      $IndexNum = 0
                      $tmpArr = @()
                      $VSWvNIC = Get-VMNetworkAdapter -ManagementOS -SwitchName $SelSWName -ErrorAction SilentlyContinue
                      foreach ($vNI in $VSWvNIC)
                      {
                        $IndexNum++
                        $IndexStr = [String]$IndexNum+")"
                        $VLANConfig = $vNI.VlanSetting
                        $BWConfig = $vNI.BandwidthSetting

                        $vNICName = $vNI.Name
                        $vNICVLANMode = $VLANConfig.OperationMode
                        $vNICAccessVLANID = $VLANConfig.AccessVlanId
                        $vNICMinBandWeight = $BWConfig.MinimumBandwidthWeight
                        $vNICBandPercentage = $vNI.BandwidthPercentage
                        $Output = New-Object PSObject
                        $Output | Add-Member Noteproperty Index $IndexStr
                        $Output | Add-Member Noteproperty Name $vNICName
                        $Output | Add-Member Noteproperty "VLANMode" $vNICVLANMode
                        $Output | Add-Member Noteproperty "VLAN ID(Access)" $vNICAccessVLANID
                        $Output | Add-Member Noteproperty "MinimumBandwidthWeight" $vNICMinBandWeight
                        $Output | Add-Member Noteproperty "BandwidthPercentage" $vNICBandPercentage
                        $tmpArr += $Output
                      }

                      Clear-Host
                      Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 5"
                      Write-Host `n"---------------------------------------"
                      Write-Host "-- Manage Virtual Network Interfaces --"
                      Write-Host -NoNewLine "-- Selected Virtual Switch: "
                      Write-Host -ForegroundColor Green $SelSWName
                      Write-Host "---------------------------------------"

                      If (! $VSWvNIC)
                      {
                        Write-Host `n"There is no Virtual Network Interface."
                        Do
                        {
                          Write-Host -NoNewline `n"Add New Virtual Network Interface? "
                          Write-Host -foregroundColor Yellow -NoNewline "[Y]"
                          Write-Host -NoNewline " or "
                          Write-Host -foregroundColor Yellow -NoNewline "[N]"
                          Write-Host -NoNewline ": "
                          $AddvNIC = Read-Host
                        }
                        While ($AddvNIC -ne "Y" -and $AddvNIC -ne "N")

                        If ($AddvNIC -eq "Y")
                        {
                          $NewNICName = Read-Host `n`n"Interface Name (Blank: Cancel)"
                          
                          If (! $NewNICName)
                          {
                            Write-Host `n"Canceled."
                            Start-Sleep 1
                            Break
                          }
                          Else
                          {
                            $NewNICMinBand = Read-Host `n"Minimum Bandwidth Weight (0-100)"
                            $NewNICVlanID = Read-Host `n"VLAN ID (Blank: No VLAN)"

                            Write-Host `n`n"Creating Virtual Network Interface. Please Wait..."
                            Add-VMNetworkAdapter -ManagementOS -Name $NewNICName -SwitchName $SelSWName
                            Set-VMNetworkAdapter -ManagementOS -Name $NewNICName -MinimumBandwidthWeight $NewNICMinBand

                            If ($NewNICVlanID)
                            {Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName $NewNICName -Access -VlanId $NewNICVlanID}
                            Else {Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName $NewNICName -Untagged}
                            Write-Host `n"Creation Succeeded."
                            Start-Sleep 1
                          }
                        }
                        Else {Break}
                      }
                      Else
                      {
                        $tmpArr | ft -AutoSize
                        Do
                        {
                          Write-Host -foregroundColor Yellow -NoNewline `n"[A]"
                          Write-Host -NoNewline "dd, "
                          Write-Host -foregroundColor Yellow -NoNewline "[R]"
                          Write-Host -NoNewline "emove, "
                          Write-Host -foregroundColor Yellow -NoNewline "[M]"
                          Write-Host -NoNewline "odify Interface or "
                          Write-Host -foregroundColor Yellow -NoNewline "[Q]"
                          Write-Host -NoNewline "uit: "
                          $vNICTask = Read-Host
                        }
                        While ($vNICTask -ne "A" -and $vNICTask -ne "R" -and $vNICTask -ne "M" -and $vNICTask -ne "Q")

                        If ($vNICTask -eq "Q") {Break}

                        Switch ($vNICTask)
                        {
                          "A"
                          {
                            $NewNICName = Read-Host `n`n"Interface Name (Blank: Cancel)"
                            If (! $NewNICName)
                            {
                              Write-Host `n"Canceled."
                              Start-Sleep 1
                              Break
                            }

                            $NewNICMinBand = Read-Host `n"Minimum Bandwidth Weight (0-100)"
                            $NewNICVlanID = Read-Host `n"VLAN ID (Blank: No VLAN)"
                            Write-Host `n`n"Creating Virtual Network Interface. Please Wait..."
                            Add-VMNetworkAdapter -ManagementOS -Name $NewNICName -SwitchName $SelSWName
                            Set-VMNetworkAdapter -ManagementOS -Name $NewNICName -MinimumBandwidthWeight $NewNICMinBand

                            If ($NewNICVlanID)
                            {Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName $NewNICName -Access -VlanId $NewNICVlanID}
                            Else {Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName $NewNICName -Untagged}
                            Write-Host `n"Creation Succeeded."
                            Start-Sleep 1
                          }

                          "R"
                          {
                            Write-Host -NoNewLine `n`n"Interface "
                            Write-Host -NoNewLine -foregroundColor Yellow "[ID] "
                            Write-Host -NoNewLine "(Blank: Cancel): "
                            $vNICtoRemove = Read-Host

                            If ($vNICtoRemove)
                            {
                              $vNICtoRemove = [Int]$vNICtoRemove-1
                              $vNICtoRemoveName = $tmpArr[$vNICtoRemove].Name
                              Do
                              {
                                Write-Host -NoNewLine `n"Removing Virtual Network Interface "
                                Write-Host -NoNewLine -foregroundColor Red $vNICtoRemoveName
                                Write-Host "."
                                Write-Host -NoNewLine "Are You Sure ? "
                                Write-Host -NoNewLine -foregroundColor Yellow "[Y]"
                                Write-Host -NoNewLine " or "
                                Write-Host -NoNewLine -foregroundColor Yellow "[N]"
                                Write-Host -NoNewLine ": "
                                $ConfirmRemovevNIC = Read-Host
                              }
                              While ($ConfirmRemovevNIC -ne "Y" -and $ConfirmRemovevNIC -ne "N")

                              If ($ConfirmRemovevNIC -eq "Y")
                              {
                                Remove-VMNetworkAdapter -ManagementOS -Name $vNICtoRemoveName
                                Write-Host `n"Removed."
                                Start-Sleep 1
                              }
                              Else
                              {
                                Write-Host `n"Canceled."
                                Start-Sleep 1
                              }
                            }
                            Else
                            {
                              Write-Host `n"Canceled."
                              Start-Sleep 1
                            }
                          }

                          "M"
                          {
                            Write-Host -NoNewLine `n`n"Interface "
                            Write-Host -NoNewLine -foregroundColor Yellow "[ID] "
                            Write-Host -NoNewLine "(Blank: Cancel): "
                            $vNICtoModify = Read-Host
                            If ($vNICtoModify)
                            {
                              $vNICtoModify = [Int]$vNICtoModify-1
                              $vNICtoModifyName = $tmpArr[$vNICtoModify].Name
                              Write-Host -NoNewLine `n"Selected Interface is "
                              Write-Host -NoNewLine -foregroundColor Green $vNICtoModifyName
                              Write-Host "."

                              Do
                              {
                                Write-Host -NoNewLine `n"Modify "
                                Write-Host -NoNewLine -foregroundColor Yellow "[V]"
                                Write-Host -NoNewLine "LAN or "
                                Write-Host -NoNewLine -foregroundColor Yellow "[B]"
                                Write-Host -NoNewLine "andwidth Weight: "
                                $vNICModifyTask = Read-Host
                              }
                              While ($vNICModifyTask -ne "V" -and $vNICModifyTask -ne "B")

                              Switch ($vNICModifyTask)
                              {
                                "V"
                                {
                                  $NewVlanID = Read-Host `n"VLAN ID (Blank: No VLAN)"
                                  Write-Host `n`n"Modifing Virtual Network Interface. Please Wait..."
                                  If ($NewVlanID)
                                  {Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName $vNICtoModifyName -Access -VlanId $NewVlanID}
                                  Else {Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName $vNICtoModifyName -Untagged}
                                  Write-Host `n"Done."
                                  Start-Sleep 1
                                }

                                "B"
                                {
                                  $NewBW = Read-Host `n"Minimum Bandwidth Weight (0-100)"
                                  Write-Host `n`n"Modifing Virtual Network Interface. Please Wait..."
                                  Set-VMNetworkAdapter -ManagementOS -Name $vNICtoModifyName -MinimumBandwidthWeight $NewBW
                                  Write-Host `n"Done."
                                  Start-Sleep 1
                                }
                              }
                            }
                            Else
                            {
                              Write-Host `n"Canceled."
                              Start-Sleep 1
                            }
                          }
                        }
                      }
                    }
                    While ($True)
                  }
                }
              }
              While ($True)
            }
          }

          If (! $VSW)
          {
            Do
            {
              Write-Host -NoNewline `n"Create New Virtual Switch? "
              Write-Host -foregroundColor Yellow -NoNewline "[Y]"
              Write-Host -NoNewline " or "
              Write-Host -foregroundColor Yellow -NoNewline "[N]"
              Write-Host -NoNewline ": "
              $CreateNewVSW = Read-Host
            }
            While ($CreateNewVSW -ne "Y" -and $CreateNewVSW -ne "N")

            If ($CreateNewVSW -eq "N") {Break}
            Else
            {
              Do
              {
                Clear-Host
                Write-Host `n`n"Searching for Available Network Interfaces. Please Wait..."

                $idx = 0
                $tmpArr = @()
                $IPs = Get-NetIPAddress | Where {$_.AddressFamily -eq "IPv4"}
                $HostNIC = Get-VMNetworkAdapter -ManagementOS
                $NICs = Get-NetAdapterBinding | Where {$_.ComponentID -eq "ms_tcpip" -and $_.Enabled -eq "True"} | Get-NetAdapter | Sort-Object -Property Name

                foreach ($Item in $NICs)
                {
                  $isAvail = 1
                  foreach ($Item1 in $HostNIC)
                  {
                    $tmpMAC = $Item.MacAddress.Replace("-","")
                    If ($tmpMAC -eq $Item1.MacAddress)
                    {
                      $isAvail = 0
                    }
                  }

                  If ($isAvail -eq 1)
                  {
                    $idx++
                    $idxStr = [String]$idx+")"
                    $IPAddress = ""
                    foreach ($Item3 in $IPs)
                    {
                      If ($Item3.InterfaceIndex -eq $Item.InterfaceIndex) {$IPAddress = $Item3.IPAddress+"/"+$Item3.PrefixLength}
                    }
                    $Output = New-Object PSObject
                    $Output | Add-Member Noteproperty Index $idxStr
                    $Output | Add-Member Noteproperty Name $Item.Name
                    $Output | Add-Member Noteproperty Description $Item.InterfaceDescription
                    $Output | Add-Member Noteproperty "IP Address" $IPAddress
                    $Output | Add-Member Noteproperty Speed $Item.LinkSpeed
                    $Output | Add-Member Noteproperty Status $Item.Status
                    $tmpArr += $Output
                  }
                }

                Clear-Host
                Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 4"
                Write-Host `n"-------------------------------"
                Write-Host "-- Create New Virtual Switch --"
                Write-Host "-------------------------------"
                $tmpArr | ft -AutoSize
                
                Do
                {
                  Write-Host -NoNewline "Select Interface "
                  Write-Host -foregroundColor Yellow -NoNewline "[ID]"
                  Write-Host -NoNewline " or "
                  Write-Host -foregroundColor Yellow -NoNewline "[Q]"
                  Write-Host -NoNewline "uit: "
                  $CreateNewVSNIC = Read-Host
                }
                While ((!$CreateNewVSNIC -or $CreateNewVSNIC -eq 0) -and $CreateNewVSNIC -ne "Q")

                If ($CreateNewVSNIC -eq "Q") {Break}

                $CreateNewVSNIC = [Int]$CreateNewVSNIC-1
                $NICName = $tmpArr[$CreateNewVSNIC].Name
                $VSWName = Read-Host `n"New Virtual Switch Name (Blank: Cancel)"
                If (! $VSWName)
                {
                  Write-Host `n"Canceled."
                  Start-Sleep 1
                  Break
                }

                Write-Host `n"Creating a New Virtual Switch. Please Wait..."
                $CreateVWS = New-VMSwitch -Name $VSWName -NetAdapterName $NICName -AllowManagementOS $False -MinimumBandwidthMode Weight
                $SetVSWBW = $CreateVWS | Set-VMSwitch -DefaultFlowMinimumBandwidthWeight 10
                $CreateVWS = Get-VMSwitch -Name $VSWName
                $CreateVWS | fl *
                Write-Host `n"Creation Succeeded."
                Write-Host `n"Press Any Key to Continue..."
                $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
                Break
              }
              While ($True)
            }
          }
        }
        While ($True)
      }

      "3"
      {
        Do
        {
          Clear-Host
          Write-Host `n`n"Retrieving Data. Please Wait..."

          $idx = 0
          $tmpArr = @()
          $NICs = Get-NetAdapterBinding | Where {$_.ComponentID -eq "ms_tcpip" -and $_.Enabled -eq "True"} | Get-NetAdapter | Sort-Object -Property Name
          $IPs = Get-NetIPAddress | Where {$_.AddressFamily -eq "IPv4"}

          foreach ($Item in $NICs)
          {
            $idx++
            $idxStr = [String]$idx+")"
            $IfName = $Item.Name
            $IfDesc = $Item.InterfaceDescription
            $Speed = $Item.LinkSpeed
            $Status = $Item.Status
            $IPAddress = ""
            $IfIPConfig = Get-NetIPInterface | Where {$_.InterfaceAlias -eq $IfName}

            If ($IfIPConfig.Dhcp -eq "Enabled") {$IPAddress = "DHCP"}
            ElseIf (! $IfIPConfig) {$IPAddress = "N/A"}
            Else
            {
              foreach ($Item1 in $IPs)
              {
                If ($Item1.InterfaceIndex -eq $Item.InterfaceIndex) {$IPAddress = $Item1.IPAddress+"/"+$Item1.PrefixLength}
              }
            }
            $Output = New-Object PSObject
            $Output | Add-Member Noteproperty Index $idxStr
            $Output | Add-Member Noteproperty Name $IfName
            $Output | Add-Member Noteproperty Description $IfDesc
            $Output | Add-Member Noteproperty "IP Address" $IPAddress
            $Output | Add-Member Noteproperty Speed $Speed
            $Output | Add-Member Noteproperty Status $Status
            $tmpArr += $Output
          }

          Clear-Host
          Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 3"
          Write-Host `n"-----------------------------------"
          Write-Host "-- Configure IP Addresses (IPv4) --"
          Write-Host "-----------------------------------"
          $tmpArr | ft -AutoSize

          Do
          {
            Write-Host -NoNewline `n"Select Interface "
            Write-Host -foregroundColor Yellow -NoNewline "[ID]"
            Write-Host -NoNewline " or "
            Write-Host -foregroundColor Yellow -NoNewline "[Q]"
            Write-Host -NoNewline "uit: "
            $ConfigIP4NIC = Read-Host
          }
          While ((!$ConfigIP4NIC -or $ConfigIP4NIC -eq 0) -and $ConfigIP4NIC -ne "Q")

          If ($ConfigIP4NIC -eq "Q") {Break}

          $ConfigIP4NIC = [Int]$ConfigIP4NIC-1
          Do
          {
            Clear-Host

            $NIC = $NICs[$ConfigIP4NIC]
            $IfName = $NIC.Name
            $IfDesc = $NIC.InterfaceDescription
            $Speed = $NIC.LinkSpeed
            $Status = $NIC.Status
            $DNS = $NIC | Get-DnsClientServerAddress -AddressFamily IPv4
            $DNS = [String]$DNS.ServerAddresses
            $IPAddress = ""
            $IfIPConfig = Get-NetIPInterface | Where {$_.InterfaceAlias -eq $IfName}

            If ($IfIPConfig.Dhcp -eq "Enabled") {$IPAddress = "DHCP"}
            ElseIf (! $IfIPConfig) {$IPAddress = "N/A"}
            Else
            {
              foreach ($Item1 in $IPs)
              {
                If ($Item1.InterfaceIndex -eq $NIC.InterfaceIndex) {$IPAddress = $Item1.IPAddress+"/"+$Item1.PrefixLength}
              }
            }
            Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 4"
            Write-Host `n"------------------------"
            Write-Host "-- Selected Interface --"
            Write-Host "------------------------"
            Write-Host `n" - Name: "$IfName
            Write-Host `n" - Description: "$IfDesc
            Write-Host `n" - IP Address: "$IPAddress
            Write-Host `n" - DNS Servers: "$DNS
            Write-Host `n" - Speed: "$Speed
            Write-Host `n" - Status: "$Status`n

            Do
            {
              Write-Host -foregroundColor Yellow -NoNewline `n"[D]"
              Write-Host -NoNewline "HCP or "
              Write-Host -foregroundColor Yellow -NoNewline "[S]"
              Write-Host -NoNewline "tatic (Blank: Cancel): "
              $IPType = Read-Host
            }
            While ($IPType -ne "D" -and $IPType -ne "S" -and $IPType -ne "")

            If (! $IPType)
            {
              Write-Host `n"Canceled."
              Start-Sleep 1
              Break
            }
            ElseIf ($IPType -eq "D")
            {
              $NIC | Remove-NetIPAddress -Confirm:$False -ErrorAction SilentlyContinue
              $NIC | Remove-NetRoute -Confirm:$False -ErrorAction SilentlyContinue
              $NIC | Set-NetIPInterface -Dhcp Enabled
              $NIC | Set-DnsClientServerAddress -ResetServerAddresses
              Write-Host `n"Done."
              Start-Sleep 1
              Break
            }

            $IP = Read-Host `n"New IP Address (Blank: Cancel)"
            If (! $IP)
            {
              Write-Host `n"Canceled."
              Start-Sleep 1
              Break
            }

            $ArrIP = $IP.Split(".")
            $IPClass = [int]$ArrIP[0]
            If ($IPClass -ge 0 -and $IPClass -le 127) {$DefaultSubnet = "255.0.0.0"}
            ElseIf ($IPClass -ge 128 -and $IPClass -le 191) {$DefaultSubnet = "255.255.0.0"}
            ElseIf ($IPClass -ge 192 -and $IPClass -le 224) {$DefaultSubnet = "255.255.255.0"}
            Else {$DefaultSubnet = "255.255.255.255"}
            $Mask = Read-Host `n"Subnet Mask (Default: "$DefaultSubnet")"
            If (! $Mask) {$Mask = $DefaultSubnet}
            $GW = Read-Host `n"Default Gateway (Optional)"

            $ArrMask = $Mask.Split(".")
            $PrefixLen = ""
            foreach ($MaskItem in $ArrMask)
            {
              $tmpPrefix = [Convert]::ToString([int32]$MaskItem,2)
              $PrefixLen = $PrefixLen + $tmpPrefix
            }
            $PrefixLen = $PrefixLen.Replace("0","")
            $PrefixLen = $PrefixLen.Length

            $NIC | Remove-NetIPAddress -Confirm:$False -ErrorAction SilentlyContinue
            $NIC | Remove-NetRoute -Confirm:$False -ErrorAction SilentlyContinue
            $NIC | Set-DnsClientServerAddress -ResetServerAddresses

            If (! $GW) {$tmp = $NIC | New-NetIPAddress -IPAddress $IP -PrefixLength $PrefixLen}
            Else {$tmp = $NIC | New-NetIPAddress -IPAddress $IP -PrefixLength $PrefixLen -DefaultGateway $GW}

            Write-Host `n"Done."`n
            Start-Sleep 1

            $DNSIP1 = Read-Host `n"Primary DNS Server IP Address (Optional)"
            If (! $DNSIP1) {Break}
            $DNSIP2 = Read-Host `n"Secondary DNS Server IP Address (Optional)"
            If (! $DNSIP2) {$NIC | Set-DnsClientServerAddress -ServerAddresses $DNSIP1}
            Else {$NIC | Set-DnsClientServerAddress -ServerAddresses $DNSIP1,$DNSIP2}

            Write-Host `n"Done."
            Start-Sleep 1
            Break
          }
          While ($True)
        }
        While ($True)
      }
    }
  }
  While ($True)
}


Function JumboFrame
{
  Do
  {
    Clear-Host
    Write-Host `n`n"Retrieving Data. Please Wait..."

    $NICs = Get-NetAdapterAdvancedProperty | Where {$_.RegistryKeyword -like "*JumboPacket"} | Sort-Object -Property Name
    $idx = 0
    $tmpArr = @()
    foreach ($Item in $NICs)
    {
      $idx++
      $idxStr = [String]$idx+")"
      $Interface = $Item | Get-NetAdapter

      $Output = New-Object PSObject
      $Output | Add-Member Noteproperty Index $idxStr
      $Output | Add-Member Noteproperty Name $Item.Name
      $Output | Add-Member Noteproperty Description $Interface.InterfaceDescription
      $Output | Add-Member Noteproperty SetValue $Item.DisplayValue
      $Output | Add-Member Noteproperty Speed $Interface.LinkSpeed
      $Output | Add-Member Noteproperty Status $Interface.Status
      $tmpArr += $Output
    }
    Clear-Host
    Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 2"
    Write-Host `n"--------------------------------------------"
    Write-Host "-- Network Interface Jumbo Frame Settings --"
    Write-Host "--------------------------------------------"
    $tmpArr| ft -AutoSize

    Do
    {
      Write-Host -NoNewline `n"Select Interface "
      Write-Host -foregroundColor Yellow -NoNewline "[ID]"
      Write-Host -NoNewline ", Ping "
      Write-Host -foregroundColor Yellow -NoNewline "[T]"
      Write-Host -NoNewline "est or "
      Write-Host -foregroundColor Yellow -NoNewline "[Q]"
      Write-Host -NoNewline "uit: "
      $NICJumboSet = Read-Host
    }
    While (!$NICJumboSet)
    
    If ($NICJumboSet -eq "T")
    {
      $tmpTargetIP = Read-Host `n`n"Target IP Address (Blank: Cancel)"
      If (!$tmpTargetIP)
      {
        Write-Host `n"Canceled."
        Start-Sleep 1
      }
      Else
       {
          $PingCmd = "Ping -f -l 8000 "+$tmpTargetIP
          Invoke-Expression -Command $PingCmd
          Write-Host `n`n"Press Any Key to Continue..."
          $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
       }
    }
    
    Clear-Host
    If ($NICJumboSet -eq "Q") {Break}

    $NICJumboSet = [Int]$NICJumboSet-1
    If ($Error) {$Error.Clear()}
    Else
    {
      Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 3"
      Write-Host `n"------------------------"
      Write-Host "-- Selected Interface --"
      Write-Host "------------------------"

      $Interface = $NICs[$NICJumboSet] | Get-NetAdapter
      $tmpArr = @()

      $Output = New-Object PSObject
      $Output | Add-Member Noteproperty Name $NICs[$NICJumboSet].Name
      $Output | Add-Member Noteproperty Description $Interface.InterfaceDescription
      $Output | Add-Member Noteproperty ConfigName $NICs[$NICJumboSet].DisplayName
      $Output | Add-Member Noteproperty SetValue $NICs[$NICJumboSet].DisplayValue
      $tmpArr += $Output
      $tmpArr| ft -AutoSize

      Do
      {
        Write-Host -foregroundColor Yellow -NoNewline `n"[E]"
        Write-Host -NoNewline "nable or "
        Write-Host -foregroundColor Yellow -NoNewline "[D]"
        Write-Host -NoNewline "isable Jumbo Frame (Blank: Cancel): "
        $EnableJumbo = Read-Host
      }
      While ($EnableJumbo -ne "E" -and $EnableJumbo -ne "D" -and $EnableJumbo -ne "")

      Switch ($EnableJumbo)
      {
        "E"
        {
          If ($NICs[$NICJumboSet].DisplayParameterType -eq 1)
          {
            $NICs[$NICJumboSet] | Set-NetAdapterAdvancedProperty -RegistryKeyword "*JumboPacket" -Registryvalue 9000
            Write-Host `n"Done."
            Start-Sleep 1
          }
          ElseIf ($NICs[$NICJumboSet].DisplayParameterType -eq 5)
          {
            $NICs[$NICJumboSet] | Set-NetAdapterAdvancedProperty -RegistryKeyword "*JumboPacket" -Registryvalue 9014
            Write-Host `n"Done."
            Start-Sleep 1
          }
        }

        "D"
        {
          If ($NICs[$NICJumboSet].DisplayParameterType -eq 1)
          {
            $NICs[$NICJumboSet] | Set-NetAdapterAdvancedProperty -RegistryKeyword "*JumboPacket" -Registryvalue 1500
            Write-Host `n"Done."
            Start-Sleep 1
          }
          ElseIf ($NICs[$NICJumboSet].DisplayParameterType -eq 5)
          {
            $NICs[$NICJumboSet] | Set-NetAdapterAdvancedProperty -RegistryKeyword "*JumboPacket" -Registryvalue 1514
            Write-Host `n"Done."
            Start-Sleep 1
          }
        }
        
        Default
        {
          Write-Host `n"Canceled."
          Start-Sleep 1
          Break
        }
      }
    }
  }
  While ($True)
}



#---------------------------------------------------#
#------------------- Script Main -------------------#
#---------------------------------------------------#
$UI = (Get-Host).UI.RawUI
$UI.BackgroundColor = "Black"
$UI.ForegroundColor = "White"
$Error.Clear()

Do
{
  Do
  {
    Clear-Host
    Write-Host -ForegroundColor White -BackgroundColor DarkGreen "Phase - 1"
    Write-Host `n"------------------------------------"
    Write-Host "-- Hyper-V Initial Configurations --"
    Write-Host "------------------------------------"
    Write-Host `n"1) Essential Settings for Hyper-V"
    Write-Host `n"2) Windows Features for Hyper-V and Failover Clustering"
    Write-Host `n"3) Physical and Virtual Network Configurations"
    Write-Host `n"4) Network Interface Jumbo Frame Settings"
    Write-Host -NoNewline `n`n"Select Task "
    Write-Host -foregroundColor Yellow -NoNewline "[ID]"
    Write-Host -NoNewline " or "
    Write-Host -foregroundColor Yellow -NoNewline "[Q]"
    Write-Host -NoNewline "uit: "
    $FunctionID = Read-Host
  }
  While ((!$FunctionID -or $FunctionID -eq 0 -or $FunctionID -gt 4) -and $FunctionID -ne "Q")

  Switch ($FunctionID)
  {
  "1" {Essential}
  "2" {WindowsFeatures}
  "3" {VirtualNetworks}
  "4" {JumboFrame}
  "Q" {
        Write-Host `n`n"Script Ended."`n`n
        Exit 0
      }
  }
}
While ($True)

 
:
Posted by 커널64