Author Posts

August 23, 2018 at 2:57 pm

$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)"

August 23, 2018 at 3:00 pm

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.

August 23, 2018 at 3:07 pm

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.

August 23, 2018 at 3:37 pm

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

 

August 23, 2018 at 8:56 pm

Thanks all very much for tips