Skip to content

Instantly share code, notes, and snippets.

@hose1021
Forked from bengarrett/hyper-v.cmd
Created March 23, 2023 13:59
Show Gist options
  • Save hose1021/e1aa8d40823e2474263f5f33d5630ff5 to your computer and use it in GitHub Desktop.
Save hose1021/e1aa8d40823e2474263f5f33d5630ff5 to your computer and use it in GitHub Desktop.

Revisions

  1. @bengarrett bengarrett revised this gist Jul 25, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions hyper-v.cmd
    Original file line number Diff line number Diff line change
    @@ -8,9 +8,9 @@ if "%1" == "/?" goto help1
    goto check_Permissions

    :check_Arguments
    if /i "%1" == "/on" goto enable
    if /i "%1" == "/off" goto disable
    goto err2
    if /i "%1" == "/on" goto enable
    if /i "%1" == "/off" goto disable
    goto err2

    :enable
    echo Enable Hyper-V.
  2. @bengarrett bengarrett created this gist Jul 25, 2014.
    59 changes: 59 additions & 0 deletions hyper-v.cmd
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    ::File: c:\terminal\cmd-scripts\hyper-v.cmd
    @echo off
    echo.

    if [%1] == [] goto help1
    if "%1" == "/?" goto help1

    goto check_Permissions

    :check_Arguments
    if /i "%1" == "/on" goto enable
    if /i "%1" == "/off" goto disable
    goto err2

    :enable
    echo Enable Hyper-V.
    bcdedit /set hypervisorlaunchtype auto
    goto reboot_Request

    :disable
    echo Disable Hyper-V.
    bcdedit /set hypervisorlaunchtype off
    goto reboot_Request

    :reboot_Request
    @echo.
    echo Please reboot your computer to apply these changes.
    goto end1

    :err1
    echo No parameter provided. Please use the following syntax.
    goto help2

    :err2
    echo %1 is not a valid parameter. Please use the following syntax.
    goto help2

    :help1
    echo Sets the hypervisorlaunchtype in the Boot Configuration Data Store.
    goto help2

    :help2
    @echo.
    echo hyper-v /on - To enable Hyper-V
    echo hyper-v /off - To disable Hyper-V
    goto end1

    :check_Permissions
    :: http://stackoverflow.com/questions/4051883/batch-script-how-to-check-for-admin-rights
    net session >nul 2>&1
    if %errorLevel% == 0 (
    goto check_Arguments
    ) else (
    echo Please run this script as an Administrator.
    echo The Boot Configuration Data Store can not be accessed as the user %USERNAME%.
    goto end1
    )

    :end1