Private/GetTicket.ps1

<#
.NOTES
    Company: BitTitan, Inc.
    Title: GetTicket.ps1
    Author: SUPPORT@BITTITAN.COM
    Requirements:
     
    Version: 1.1
    Date: DECEMBER 22, 2016
 
    Disclaimer: This script is provided ‘AS IS’. No warrantee is provided either expresses or implied.
 
    Copyright: Copyright© 2016 BitTitan. All rights reserved.
     
.SYNOPSIS
  Passes the environment, and MigrationWiz credentials to get an authentication token for MigrationWiz.
 
.DESCRIPTION
  Helper function for the Sync-ADtoO365 tool.
 
#>


function GetTicket 
{
[CmdletBinding()]

    Param (
        [System.Management.Automation.Credential()]$MigrationWizCredentials,
        [string]$environment
    )

    Begin {}

    Process 
    {

        # get new ticket if we don't already have one or it's expired
        if( ($ticket -eq $null) -or ( $ticket.ExpirationDate -lt (Get-Date).ToUniversalTime() ) )
        {
            # get new ticket
            Try 
            {
                $ticket = Get-MW_Ticket -Credentials $migrationwizCredentials -Environment $environment -Verbose -ErrorAction Stop
            }
            Catch 
            {
                throw
            }
        }

        return $ticket
    
    } # end process

    End {}

} # end GetTicket function