Creating a banner GUI

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 11 months ago.

  • Author
    Posts
  • #5810

    by Lery at 2013-04-16 07:30:50

    So this is not really a GUI in the traditional sense. I plan on learning that later on. For now, I found a nice example on the Scripting Guys repository. I'm using this as a foundation to add my own items. What I would like to know is how can I setup the code below to not just exit after making a choice of either 1, 2, or 3? I would like to add a 4th option to exit. That way I can hit 1, it runs, and the banner options come back. Not until I hit 4, would the script just exit. Here is the sample code that I'm using as a foundation. I'm not using the uninstall-windowsfeature section. It could be as simple as a WMI query.

    < #
    The sample scripts are not supported under any Microsoft standard support
    program or service. The sample scripts are provided AS IS without warranty
    of any kind. Microsoft further disclaims all implied warranties including,
    without limitation, any implied warranties of merchantability or of fitness for
    a particular purpose. The entire risk arising out of the use or performance of
    the sample scripts and documentation remains with you. In no event shall
    Microsoft, its authors, or anyone else involved in the creation, production, or
    delivery of the scripts be liable for any damages whatsoever (including,
    without limitation, damages for loss of business profits, business interruption,
    loss of business information, or other pecuniary loss) arising out of the use
    of or inability to use the sample scripts or documentation, even if Microsoft
    has been advised of the possibility of such damages.
    #>

    #requires -Version 2

    function OSCgetid ($id)
    {
    if ($id -like "[123]")
    {
    switch ($id)
    {
    "1" {Uninstall-WindowsFeature Server-Gui-Mgmt-Infra,Server-Gui-Shell}
    "2" {Install-WindowsFeature Server-Gui-Mgmt-Infra,Server-Gui-Shell}
    "3" {
    Import-Module Dism
    Enable-WindowsOptionalFeature -online -Featurename ServerCore-FullServer,Server-Gui-Shell,Server-Gui-Mgmt
    }
    }
    }
    else
    {
    Write-Warning -Message "Incorrect input!"
    [string]$id=Read-Host -Prompt "Enter the number to select an option"
    OSCgetid $id
    }
    }

    $banner=@'
    ==============================================================
    Switch between GUI and server Core
    ==============================================================
    [1] Switch to server CORE
    [2] Switch to GUI
    [3] Install GUI from online resource
    '@

    Write-Host $banner
    [string]$ID=Read-Host -Prompt "Enter the number to select an option"
    OSCgetid $id
    write-host "It Will take effect after reboot, do you want to reboot?"
    [string]$Reboot = Read-Host -Prompt "[Y] Yes [N] No (default is 'N')"

    if ($Reboot -eq "y" -or $Reboot -eq "yes") {Restart-Computer}

    by Nobody at 2013-04-16 10:23:01

    You basically just need to throw in a Do-Until loop


    < #
    The sample scripts are not supported under any Microsoft standard support
    program or service. The sample scripts are provided AS IS without warranty
    of any kind. Microsoft further disclaims all implied warranties including,
    without limitation, any implied warranties of merchantability or of fitness for
    a particular purpose. The entire risk arising out of the use or performance of
    the sample scripts and documentation remains with you. In no event shall
    Microsoft, its authors, or anyone else involved in the creation, production, or
    delivery of the scripts be liable for any damages whatsoever (including,
    without limitation, damages for loss of business profits, business interruption,
    loss of business information, or other pecuniary loss) arising out of the use
    of or inability to use the sample scripts or documentation, even if Microsoft
    has been advised of the possibility of such damages.
    #>

    #requires -Version 2

    function OSCgetid ($id)
    {
    if ($id -like "[1234]")
    {
    switch ($id)
    {
    "1" {Uninstall-WindowsFeature Server-Gui-Mgmt-Infra,Server-Gui-Shell}
    "2" {Install-WindowsFeature Server-Gui-Mgmt-Infra,Server-Gui-Shell}
    "3" {
    Import-Module Dism
    Enable-WindowsOptionalFeature -online -Featurename ServerCore-FullServer,Server-Gui-Shell,Server-Gui-Mgmt
    }
    "4" {
    exit
    }
    }
    }
    else
    {
    Write-Warning -Message "Incorrect input!"
    [string]$id=Read-Host -Prompt "Enter the number to select an option"
    OSCgetid $id
    }
    }

    Do {
    $banner=@'
    ==============================================================
    Switch between GUI and server Core
    ==============================================================
    [1] Switch to server CORE
    [2] Switch to GUI
    [3] Install GUI from online resource
    [4] Exit
    '@

    Write-Host $banner
    [string]$ID=Read-Host -Prompt "Enter the number to select an option"
    OSCgetid $id
    write-host "It Will take effect after reboot, do you want to reboot?"
    [string]$Reboot = Read-Host -Prompt "[Y] Yes [N] No (default is 'N')"

    if ($Reboot -eq "y" -or $Reboot -eq "yes") {Restart-Computer}
    }Until ($id -eq "4")

    by Lery at 2013-04-16 11:17:12

    Thank you Nobody! Worked great.

You must be logged in to reply to this topic.