towershell.com – All about Windows & Powershell

Powershell ile Secenek Yonetimi

Powershell icinde kullaniciya soru sorarak ondan gelen yaniti parameter olarak kullanmak elbette mumkun. Bunun bir cok cesidi olsa da bugun bunlardan en gorsel olanini taniyacagiz.

System.Management.Automation.Host.ChoiceDescription objesini kullanarak keni seceneklerimizi belirliyoruz ve akabinde basit bir Switch ile kullanicinin sectigi degeri ekrana yaziriyoruz. Bunu cok farkli senaryolarda kullanabilirsiniz.

$Izmir
=
New-Object
System.Management.Automation.Host.ChoiceDescription
‘&Izmir’

$Istanbul
=
New-Object
System.Management.Automation.Host.ChoiceDescription
‘I&stanbul’

$Ankara
=
New-Object
System.Management.Automation.Host.ChoiceDescription
‘&Ankara’

$Eskisehir
=
New-Object
System.Management.Automation.Host.ChoiceDescription
‘&Eskisehir’

$Antalya
=
New-Object
System.Management.Automation.Host.ChoiceDescription
‘A&ntalya’

 

 

$secenekler
=
[System.Management.Automation.Host.ChoiceDescription[]]($izmir, $Istanbul, $Ankara, $Eskisehir, $Antalya)

 

 

$Baslik
=
‘Sehir’

$Soru
=
‘Yasadiginiz sehir hangisi?’

$Sonuc
=
$host.ui.PromptForChoice($Baslik, $Soru, $secenekler,
0)

 

Ben Istanbul’u sectigim icin sonuc da ona gore sekillendi elbette!

switch ($Sonuc)

{


0 { ‘Yasadiginiz sehir: Izmir ‘ }


1 { ‘Yasadiginiz sehir: Istanbul’ }


2 { ‘Yasadiginiz sehir: Ankara’ }


3 { ‘Yasadiginiz sehir: Eskisehir’ }


4 { ‘Yasadiginiz sehir: Antalya’ }

}

 

Yazıyı Paylaş! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Technorati
  • Twitter
Updated: January 16, 2019 — 10:09 pm
TOWERSHELL - All About Windows Powershell © 2014 Frontier Theme