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

 
Participant
3 months, 3 weeks ago.

  • Author
    Posts
  • #109751

    Participant
    Points: 3
    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 = 'http://www.overpass-api.de/api/xapi?node[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

    Keymaster
    Points: 1,704
    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

    Participant
    Points: 342
    Helping Hand
    Rank: Contributor

    Another option is a WPF GUI:

    https://mcpmag.com/articles/2016/04/28/building-ui-using-powershell.aspx

    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

    Participant
    Points: 36
    Rank: Member

    To get you started with a GUI you could check out  https://poshgui.com/

     

  • #109784

    Participant
    Points: 331
    Helping Hand
    Rank: Contributor
  • #109790

    Participant
    Points: 3
    Rank: Member

    Thanks all very much for tips

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