Udostępnij za pośrednictwem


Using PowerShell to look up USCF member info

If you are one of the chess players who play rated USCF (United States Chess Federation) games, you may have used their look up tool to find someone’s rating and other details, or may be your own after you completed a tournament.

Being a PowerShell geek, I had to figure out how can I fetch the same information using script or a function. Now that I have it, I’m sharing it here with you.

For those of you who have nothing to do with Chess, you may still want to look at the script to learn few cool thing like using objects and adding properties to a custom object, using post method to retrieve data from a webpage using values defined in a variable and using comment based help in your script file.

Here’s what the script does:

  1. Aoccepts input in form of Lastname, Firstname and wildcard. Lastname is required, firstname and wildcard are optoinal.
  2. Accepts input in form of USCF ID. Step 1 and 2 are mutually exclusive. You can only use one or the other.
  3. Checks if computer is connected to internet. We can’t fetch data from internet otherwise, can we?
  4. Validates all variables and fetches USCF member data as per the query if no errors found in validation.
  5. Allows output to be sent to csv file using –OutFile parameter. Output to console is suppressed if sent to file.

For brevity, I am not posting code in the post. You can download the file here.

Comments

  • Anonymous
    January 01, 2003
    Don, You are correct in saying functions shouldn't care about output, just output an object. And that's exactly what I am doing by default. -Outfile is just another option for a user who isn't necessarily well versed with powershell and just want to use the functionality I offer through that parameter. Sometimes, users just want script to do the work. And it isn't just one instance, I have seen many where they specifically want script to be able to write output to given file, I am just simplifying that for them. For a poweruser who knows their options will definately have ability to manipulate default output in whichever way they want! :) Thanks, Bhargav

  • Anonymous
    April 05, 2011
    The comment has been removed