Darrell Porter
asked on
Powershell: More elegant method of creating a visual interface
I have the following code block:
I am trying to write a more complete Powershell-based interface to Cisco MEraki's API.
Thank you in advance!
$tspan = @(
New-Object -TypeName PSObject -Property @{'id'='01';'name'='Previous hour';'seconds'='3600'}
New-Object -TypeName PSObject -Property @{'id'='02';'name'='Previous 2 hours';'seconds'='7200'}
New-Object -TypeName PSObject -Property @{'id'='03';'name'='Previous 4 hours';'seconds'='14400'}
New-Object -TypeName PSObject -Property @{'id'='04';'name'='Previous 8 hours';'seconds'='28800'}
New-Object -TypeName PSObject -Property @{'id'='05';'name'='Previous day';'seconds'='86400'}
New-Object -TypeName PSObject -Property @{'id'='06';'name'='Previous week';'seconds'='604800'}
New-Object -TypeName PSObject -Property @{'id'='07';'name'='Previous 2 weeks';'seconds'='1209600'}
New-Object -TypeName PSObject -Property @{'id'='08';'name'='Previous month';'seconds'='2419200'}
)
$tmspan = ($tspan | Select-Object -Property name, seconds | Sort-object -Property id | out-gridview -OutputMode Single -Title "Select a timeframe").seconds
Is there a more elegant / best-practice method of creating this interface?I am trying to write a more complete Powershell-based interface to Cisco MEraki's API.
Thank you in advance!
& $selection.Script
should be
selection.Seconds
But I think it doesn't really improve the interface, only how to feed it. A "proper" interface IMO requires .NET (XAML) or something similar, a GUI form designed for the particular purpose.
Yep … I had a copy/paste error, thanks. However, I believe it should be:
$selection.Seconds
I totally agree about it only improving the feed. Not sure why the ID field is needed, since it comes out in the same order it was entered.
You believe correct.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I will try out the GUI tomorrow. Thank you for that.
I appreciate all of your responses.
I appreciate all of your responses.
ASKER
Thank you, Gentlemen.
I had not considered using a "genuine" GUI as I am often asked for Quick & Dirty solutions and the picker was the easiest thing to implement.
I do have to tweak oBda's code because I need to reference a specific, limited set of times (those specified in my original code snippet) due to the API being used (Cisco-Meraki) and the defined business needs.
I had not considered using a "genuine" GUI as I am often asked for Quick & Dirty solutions and the picker was the easiest thing to implement.
I do have to tweak oBda's code because I need to reference a specific, limited set of times (those specified in my original code snippet) due to the API being used (Cisco-Meraki) and the defined business needs.
Open in new window