get value from user

Welcome Forums General PowerShell Q&A get value from user

This topic contains 5 replies, has 5 voices, and was last updated by

7 months ago.

  • Author
  • #109751

    Points: 5
    Rank: Member

    $minLon = Read-Host "Please enter minLon"

    $minLat = Read-Host "Please enter minLat"

    $maxLon = Read-Host "Please enter maxLon"

    $maxLat = Read-Host "Pleaes enter maxLat"

    Hi everyone. I am new in poershell and i wrote this code with your help and it works very good but now i want get values from user with window (like pop window then user can enter values) how can i modify this code please give me tips. Thanks very much.

    $url = '[bbox= {0},{1},{2},{3}][natural=tree][@meta]' -f $minLon,$minLat,$maxLon,$maxLat

    $output = "C:\Users\alo\Desktop\Montreal.osm"
    $start_time = Get-Date

    Invoke-WebRequest -Uri $url -OutFile $output
    Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

  • #109759

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    PowerShell itself doesn't have any native "pop up" for gathering information; it's a command-line shell, not a graphical development environment. You can certainly use .NET to create a GUI, but it's not just a simple line of code. SAPIEN's PowerShell Studio product might be an easy way to get into GUI programming if you've not done it before, but I'll caution you that it's a BIG space.

    You could alternately use the VisualBasic InputBox method for something quick and dirty; Google "PowerShell InputBox" and you'll find several examples.

  • #109772

    Points: 639
    Helping Hand
    Rank: Major Contributor

    Another option is a WPF GUI:

    When you are getting input, especially from Read-Host, you can get into a rabbit hole. Enter a color and put 10, then you start adding code to validation and you have a complex script with loops. GUI's are built to do validation and enter data, so if you have to get data then a form is your best bet. As Don suggested, you can use Sapien's tool, but if you aren't building a lot of forms I would go the cheap route and leverage a combination of Visual Studio and Powershell.

  • #109780

    Points: 69
    Rank: Member

    To get you started with a GUI you could check out


  • #109784

    Points: 1,154
    Helping Hand
    Rank: Community Hero
  • #109790

    Points: 5
    Rank: Member

    Thanks all very much for tips

The topic ‘get value from user’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort