Advertisement
Guest User

Untitled

a guest
May 19th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Menu
  2. {
  3.     param
  4.     (
  5.         [Parameter(Mandatory = $true)]
  6.         [string]
  7.         $Title,
  8.  
  9.         [Parameter(Mandatory = $true)]
  10.         [array]
  11.         $Options
  12.     )
  13.  
  14.     $MaxValue = $Options.Count - 1
  15.     $Selection = 0
  16.     $EnterPressed = $false
  17.  
  18.     Clear-Host
  19.  
  20.     while ($EnterPressed -eq $false)
  21.     {
  22.         Write-Host "$Title"
  23.  
  24.         for ($i = 0; $i -le $MaxValue; $i++)
  25.         {
  26.             if ($i -eq $Selection)
  27.             {
  28.                 Write-Host "[ $($Options[$i]) ]" -BackgroundColor Cyan -ForegroundColor Black
  29.             }
  30.             else
  31.             {
  32.                 Write-Host "  $($Options[$i])  "
  33.             }
  34.         }
  35.  
  36.         $KeyInput = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown").VirtualKeyCode
  37.  
  38.         switch ($KeyInput)
  39.         {
  40.             "13"
  41.             {
  42.                 # enter key
  43.                 $EnterPressed = $true
  44.                 return $Selection
  45.                 Clear-Host
  46.                 break
  47.             }
  48.  
  49.             "38"
  50.             {
  51.                 # down key
  52.                 if ($Selection -eq 0)
  53.                 {
  54.                     $Selection = $MaxValue
  55.                 }
  56.                 else
  57.                 {
  58.                     $Selection -= 1
  59.                 }
  60.                 Clear-Host
  61.                 break
  62.             }
  63.  
  64.             "40"
  65.             {
  66.                 # up key
  67.                 if ($Selection -eq $MaxValue)
  68.                 {
  69.                     $Selection = 0
  70.                 }
  71.                 else
  72.                 {
  73.                     $Selection +=1
  74.                 }
  75.                 Clear-Host
  76.                 break
  77.             }
  78.             Default
  79.             {
  80.                 Clear-Host
  81.             }
  82.         }
  83.     }
  84. }
  85.  
  86. if ($RU)
  87. {
  88.     $Title = "Выберите букву диска"
  89. }
  90. else
  91. {
  92.     $Title = "Choose the drive letter"
  93. }
  94. $Options = (Get-Disk | Where-Object -FilterScript {$_.BusType -ne "USB"} | Get-Partition | Get-Volume | Where-Object -FilterScript {$null -ne $_.DriveLetter}).DriveLetter
  95. Menu -Title $Title -Options $Options
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement