Skip to main content

Using Here-Strings to help search United Airlines for Flight Dates

As many of you know, I am fortunate to teach Windows PowerShell, Server, and Client all over the world.  One thing that I do not do very often is use my air miles.  This is has been a very deliberate action because I wanted to make sure that when my wife decides to fly to Europe with me, she will do so in style. 

Well, the time has come.  I’m heading over to Europe to speak at the PowerShell Conference in a few months and my wife and I are going to spend some time together hunting down what we hope will be distant relatives and doing a little sightseeing.  So, I’m burning the air miles to fly family to my home to house sit and for us to fly over the pond in United Polaris Class.  My wife does not like long flights so I am determine to spend the air miles wisely to make sure she is as comfortable as possible.  I’ve made the flight many times in coach, but I would be a bad husband if I did not splurge a bit on my wife. Below is the difference.


Business/Polaris

What I usually fly…. Economy.


Our schedule is extremely flexible so I’m searching all of the airports in central Europe for days when United puts a premium cabin “on sale”, so to speak, for award mile use.  To help make this daily ritual less time consuming, and to give me a good lesson to share on Here-Strings with my class, I came up with the code below.

A few things first.  If you have a United Mileage Plus account, open your default web browser and log in.  Leave the browser open when you execute the code. Otherwise the queries will not be executed with your account.

You will also need to manually search for award travel to each destination.  You will need to replace my URL strings with yours for each search that you make.

Finally, you will need to replace the date component of the URL with $FlightDate.  Look for a date with a format of YYYY-MM-DD in the URL from United.  It is easy to find.

Once done, just save the code and press F5 to put it in memory. (You will need to change the default values of the parameters to meet your desired travel date. I marked the 3 places in the param block of the code.)

Type Search-United and press Enter.  All of your queries will run at the same time.  Remember to start this process 6 months in advance if possible.  This will help you find more award mile saving dates.

Function Search-United
{
[CmdletBinding()]
Param (
    [Int]
    $Month = <#Replace with your default Month#>,
   
    [Int]
    $Day = <#Replace with your default Day#>,
   
    [Int]
    $Year = <#Replace with your default Year#>
    )

#Create a DateTime object based on the flight date.
[DateTime]$Date = "$Month-$Day-$Year"

# Convert that DateTime object into the format the United website requires.
$FlightDate = $Date.GetDateTimeFormats().split("`n")[5]

# Here-String to list all destinations to check.
$SearchList = @"
https://www.united.com/ual/en/us/flight-search/book-a-flight/results/awd?f=PHX&t=MUC&d=$FlightDate&tt=1&at=1&sc=7&px=2&taxng=1&idx=1
https://www.united.com/ual/en/us/flight-search/book-a-flight/results/awd?f=PHX&t=FRA&d=$FlightDate&tt=1&at=1&sc=7&px=2&taxng=1&idx=1
https://www.united.com/ual/en/us/flight-search/book-a-flight/results/awd?f=PHX&t=NUE&d=$FlightDate&tt=1&at=1&sc=7&px=2&taxng=1&idx=1
https://www.united.com/ual/en/us/flight-search/book-a-flight/results/awd?f=PHX&t=SZG&d=$FlightDate&tt=1&at=1&sc=7&px=2&taxng=1&idx=1
https://www.united.com/ual/en/us/flight-search/book-a-flight/results/awd?f=PHX&t=VIE&d=$FlightDate&tt=1&at=1&sc=7&px=2&taxng=1&idx=1
https://www.united.com/ual/en/us/flight-search/book-a-flight/results/awd?f=PHX&t=PAR&d=$FlightDate&tt=1&at=1&sc=7&px=2&taxng=1&idx=1
https://www.united.com/ual/en/us/flight-search/book-a-flight/results/awd?f=PHX&t=GVA&d=$FlightDate&tt=1&at=1&sc=7&px=2&taxng=1
https://www.united.com/ual/en/us/flight-search/book-a-flight/results/awd?f=PHX&t=ZRH&d=$FlightDate&tt=1&at=1&sc=7&px=2&taxng=1&idx=1
https://www.united.com/ual/en/us/flight-search/book-a-flight/results/awd?f=PHX&t=MIL&d=$FlightDate&tt=1&at=1&sc=7&px=2&taxng=1&idx=1
https://www.united.com/ual/en/us/flight-search/book-a-flight/results/awd?f=PHX&t=VCE&d=$FlightDate&tt=1&at=1&sc=7&px=2&taxng=1&idx=1
https://www.united.com/ual/en/us/flight-search/book-a-flight/results/awd?f=PHX&t=ROM&d=$FlightDate&tt=1&at=1&sc=7&px=2&taxng=1&idx=1
"@

# Open a web page for each destination.
$SearchList.Split("`n") | ForEach-Object {Start-Process -FilePath $_}

<#
.SYNOPSIS
Allows you to search multiple destinations at United Airlines.

.DESCRIPTION
Allows you to search multiple destinations at United Airlines.

First you must open your default web browser and log into your United Mileage
Plus account.  Mileage Plus members receive better access to award miles
savings so you should see more options.

Setup:
You must manually search each destination and make sure to select
"Award Travel" on the website.

Copy the web address into the Here-String above. Replace the date in
the string with $FlightDate.  The string to replace will bi in the
format YYYY-MM-DD.

Run this code when you want to check for award travel.

.PARAMETER Month
The numeric value of the month to travel.

.PARAMETER Day
The numeric value of the day to travel.

.PARAMETER Year
The numeric value of the year to travel.

.Example
Search-United

Opens the United website and looks for award travel on the default dates.

.Example
Search-United -Month 6 -Day 15 -Year 2017

Opens the United website and looks for award travel June 15, 2017.

.NOTES
===============================================================================
== Cmdlet: Search-United                                                     ==
== Author: Jason A. Yoder                                                    ==
== Company: MCTExpert of Arizona                                             ==
== Date: December 21, 2017                                                   ==
== Copyright: All rights reserved.                                           ==
== Version: 1.0.0.0                                                          ==
== Legal: The user assumes all responsibility and liability for the usage of ==
== this PowerShell code.  MCTExpert of Arizona, Its officers, shareholders,  ==
== owners, and their relatives are not liable for any damages.  As with all  ==
== code, review it and understand it prior to usage.  It is recommended that ==
== this code be fully tested and validated in a test environment prior to    ==
== usage in a production environment.                                        ==
==                                                                           ==
== Does this code make changes: NO                                           ==
===============================================================================
#>

}


Comments

Popular posts from this blog

Adding a Comment to a GPO with PowerShell

As I'm writing this article, I'm also writing a customization for a PowerShell course I'm teaching next week in Phoenix.  This customization deals with Group Policy and PowerShell.  For those of you who attend my classes may already know this, but I sit their and try to ask the questions to myself that others may ask as I present the material.  I finished up my customization a few hours ago and then I realized that I did not add in how to put a comment on a GPO.  This is a feature that many Group Policy Administrators may not be aware of. This past summer I attended a presentation at TechEd on Group Policy.  One organization in the crowd had over 5,000 Group Policies.  In an environment like that, the comment section can be priceless.  I always like to write in the comment section why I created the policy so I know its purpose next week after I've completed 50 other tasks and can't remember what I did 5 minutes ago. In the Group Policy module for PowerShell V3, th

Return duplicate values from a collection with PowerShell

If you have a collection of objects and you want to remove any duplicate items, it is fairly simple. # Create a collection with duplicate values $Set1 = 1 , 1 , 2 , 2 , 3 , 4 , 5 , 6 , 7 , 1 , 2   # Remove the duplicate values. $Set1 | Select-Object -Unique 1 2 3 4 5 6 7 What if you want only the duplicate values and nothing else? # Create a collection with duplicate values $Set1 = 1 , 1 , 2 , 2 , 3 , 4 , 5 , 6 , 7 , 1 , 2   #Create a second collection with duplicate values removed. $Set2 = $Set1 | Select-Object -Unique   # Return only the duplicate values. ( Compare-Object -ReferenceObject $Set2 -DifferenceObject $Set1 ) . InputObject | Select-Object – Unique 1 2 This works with objects as well as numbers.  The first command creates a collection with 2 duplicates of both 1 and 2.   The second command creates another collection with the duplicates filtered out.  The Compare-Object cmdlet will first find items that are diffe

How to list all the AD LDS instances on a server

AD LDS allows you to provide directory services to applications that are free of the confines of Active Directory.  To list all the AD LDS instances on a server, follow this procedure: Log into the server in question Open a command prompt. Type dsdbutil and press Enter Type List Instances and press Enter . You will receive a list of the instance name, both the LDAP and SSL port numbers, the location of the database, and its status.