PowerShell Cmdlets

Developer
Aug 21, 2014 at 6:54 PM
Hey

Is anyone here familiar with PowerShell scripting? I know that it's possible to make custom cmdlets that call managed code in .NET libraries. I think it would be really cool if we could provide a PowerShell API for GW2.NET.

MSDN: http://msdn.microsoft.com/en-us/library/dd878294(v=vs.85).aspx

I don't have any real PowerShell experience, so I can't write up an example. I just know what PowerShell is, and that we should make this happen.
Developer
Aug 23, 2014 at 8:30 AM
Edited Aug 23, 2014 at 1:31 PM
Turns out that PowerShell is already capable of retrieving and parsing JSON objects using the Invoke-RestMethod cmdlet.
before

It's nowhere near as flexible as a real GW2.NET-based implementation though.

edit

Here's the same shell script as before, this time using GW2.NET and custom-written cmdlets.

after
Developer
Aug 24, 2014 at 2:08 PM
Alright, here's an advanced use case that shows where the power and flexibility of GW2.NET comes in.

Example
Get-Items (Get-Items)[0..99] | Format-Table
-or- same as above, instead using named parameters
Get-Items -Id (Get-Items)[0..99] -Culture EN | Format-Table
Meaning
From left to right: get item details for the first 100 discovered item identifiers, request the English version, and format the output as a table.

PS
Coordinator
Aug 30, 2014 at 11:40 PM
So the user would be able to use GW2.NET from PS? Sweet.
Developer
Aug 31, 2014 at 8:05 AM
Pretty much. Nothing ever stopped people from using GW2.NET in PowerShell, but the code to do that looks awkward. What I want to do is write custom commands (cmdlets) that make the scripts look clean, as in the examples above.
Developer
Sep 2, 2014 at 8:30 AM
Just thought of a real-world example. You might want to monitor the build number for game updates. You don't want your main program to maintain an infinite loop for it, and writing a full windows service is also overkill. PowerShell is perfect for this scenario when combined with Windows Task Scheduler. You can then run other PowerShell commands when a game update is detected, or even transfer execution to your main program.
Coordinator
Sep 3, 2014 at 12:02 PM
Definetly sounds very useful