Functions/Public/EPCOther.ps1

Function Get-EPCTestPlan {
    <#
        .SYNOPSIS
        Return a list of EPC test plans
         
        .DESCRIPTION
        Return a list of EPC test plans
         
        .EXAMPLE
        Get-EPCTestPlan
 
        .NOTES
        Version 1.0
    #>

    
    [cmdletbinding()]
    Param (
        [switch]$UseXML
    )
    
    Begin {
        Connect-EPCController

        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCCred = New-Object -TypeName EPC.ActiveCtrl.CredentialsType
            $EPCCred.username = $Global:EPControllerCred.UserName
            $EPCCred.password = $Global:EPControllerCred.GetNetworkCredential().Password
        }
        Else {
            $ProgressPreference = 'SilentlyContinue'
        }
    }
    Process {
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCListTestPlansParams = New-Object -TypeName EPC.ActiveCtrl.ListTestPlansParametersType
            $EPCListTestPlansParams.credentials = $EPCCred

            $TestPlanResults = $Global:EPCWSDL_ActiveCtrl.listTestPlans($EPCListTestPlansParams)
            
            Write-Verbose $TestPlanResults.result
            
            If ($TestPlanResults.result -eq 'success') {
                Return $TestPlanResults.TestPlanList
            }
            Else {
                Throw $TestPlanResults.result
            }
        }
        Else {
            Write-Verbose 'Using XML to pull test plan list'
            $PwdEscaped = [System.Security.SecurityElement]::Escape($Global:EPControllerCred.GetNetworkCredential().Password)
            [xml]$SOAPReq = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
                xmlns:urn='urn:telchemyActiveCtrl'>
                 <soapenv:Header/>
                 <soapenv:Body>
                 <urn:listTestPlansParameters>
                <credentials>
                <username>$($Global:EPControllerCred.UserName)</username>
                <password>$PwdEscaped</password>
                </credentials>
                 </urn:listTestPlansParameters>
                 </soapenv:Body>
                </soapenv:Envelope>"


            $SOAPFQDN = "https://$Global:EPControllerFQDN/telchemywebservices/services/telchemyActiveCtrlService"
            Write-Verbose $SOAPFQDN
            Write-Verbose $SOAPReq.OuterXML

            If ($Global:EPC_UseSOAPHeader) {
                $Headers = @{'SOAPAction' = 'urn:telchemyActiveCtrl/listTestPlansParameters'}
            } Else {
                $Headers = @{}
            }

            
            [xml]$XMLResponse = (Invoke-WebRequest -UseBasicParsing -Method POST -URI $SOAPFQDN -Headers $Headers -Body $SOAPReq -ContentType 'text/xml').Content
            $TestPlanResults = $XMLResponse.Envelope.Body.listTestPlansResults
            
            If ($TestPlanResults.result -eq 'success') {
                [psobject]$TestPlans = $TestPlanResults.TestPlanList.testplan | ConvertFrom-XMLElement
                Return $TestPlans
            }
            Else {
                Throw $TestPlanResults.result
            }
        }
    }
}



#################################################################################################################################################
# #
# EPC Service Functions #
# #
#################################################################################################################################################

Function Get-EPCService {
    <#
        .SYNOPSIS
        Return list of EPC services
          
        .DESCRIPTION
        Return list of EPC services
          
        .PARAMETER ServiceClass
        Limit results to only a specific service class
          
        .EXAMPLE
        Get-EPCService -ServiceClass VOIP
        Returns service information about all VOIP services
  
        .NOTES
        Version 1.0
    #>

    
    [cmdletbinding()]
    Param (
        [Parameter(Mandatory=$False)]
        [ValidateSet('Composite','Interface','IPSec','IPTV','NetApp','NetSVC','NetTrans','Network','Other','System','TCP','VidConf','VOIP', IgnoreCase=$True)]
        [string]$ServiceClass
    )
    
    Begin {
        Connect-EPCController
        
        $EPCCred = New-Object -TypeName EPC.SvcMgmt.CredentialsType
        $EPCCred.username = $Global:EPControllerCred.UserName
        $EPCCred.password = $Global:EPControllerCred.GetNetworkCredential().Password
    }
    Process {
        $EPCListServicesParams = New-Object -TypeName EPC.SvcMgmt.ListServicesParametersType
        $EPCListServicesParams.credentials = $EPCCred
        
        If ($ServiceClass) {
            $EPCListServicesParams.serviceClass = $ServiceClass
            $EPCListServicesParams.serviceClassSpecified = $True
        }
        
        $ServiceResults = $Global:EPCWSDL_SvcMgmt.listServices($EPCListServicesParams)
        Write-Verbose $ServiceResults.result
        
        If ($ServiceResults.result -eq 'success') {
            Return $ServiceResults.ServiceList
        }
        Else {
            Throw $ServiceResults.result
        }            
    }
}


#################################################################################################################################################
# #
# EPC Resource Group Functions #
# #
#################################################################################################################################################

Function Get-EPCResourceGroup {
    <#
        .SYNOPSIS
        Return list of EPC resource groups
         
        .DESCRIPTION
        Return list of EPC resource groups
         
        .PARAMETER ParentRGID
        Limit results to only a specific resource group
         
        .EXAMPLE
        Get-EPCResourceGroup
 
        .NOTES
        Version 1.0
    #>

    
    [cmdletbinding()]
    Param (
        [Parameter(Mandatory=$False)]
        [int]$ParentRGID,
        [Parameter(Mandatory=$False)]
        [int]$ResultSize = 1000,
        [switch]$UseXML
    )
    Begin {
        Connect-EPCController
        
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCCred = New-Object -TypeName EPC.ResGrpMgmt.CredentialsType
            $EPCCred.username = $Global:EPControllerCred.UserName
            $EPCCred.password = $Global:EPControllerCred.GetNetworkCredential().Password
        }
        Else {
            $ProgressPreference = 'SilentlyContinue'
        }
    }
    Process {
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCListResourceGroupParams = New-Object -TypeName EPC.ResGrpMgmt.ListResourceGroupParametersType
            $EPCListResourceGroupParams.credentials = $EPCCred
            $EPCListResourceGroupParams.maxNumber = $ResultSize
            
            If ($ParentRGID) {
                $RGRelation = New-Object -TypeName EPC.ResGrpMgmt.ResourceGroupRelationshipMapType
                $RGRelation.RGID = $ParentRGID
                $FilterType = New-Object -TypeName EPC.ResGrpMgmt.ResourceGroupFilterType
                $FilterType.ItemElementName = 'RGrelation'
                $FilterType.Item = $RGRelation
                $EPCListResourceGroupParams.filter = $FilterType
            }
            
    
            $ResourceGroupResults = $Global:EPCWSDL_ResGrpMgmt.listResourceGroups($EPCListResourceGroupParams)
            Write-Verbose $ResourceGroupResults.result
            
            If ($ResourceGroupResults.result -eq 'success') {
                Return $ResourceGroupResults.ResourceGroupList
            }
            Else {
                Throw $ResourceGroupResults.result
            }
        }
        Else {
            Write-Verbose 'Using XML to pull resource group list'
            $PwdEscaped = [System.Security.SecurityElement]::Escape($Global:EPControllerCred.GetNetworkCredential().Password)
            [xml]$SOAPReq = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
                xmlns:urn='urn:telchemyRsrcGroupMgmt'>
                 <soapenv:Header/>
                 <soapenv:Body>
                 <urn:listResourceGroupParameters>
                <credentials>
                <username>$($Global:EPControllerCred.UserName)</username>
                <password>$PwdEscaped</password>
                </credentials>
                 </urn:listResourceGroupParameters>
                 </soapenv:Body>
                </soapenv:Envelope>"

            
            # Add filter options if entered
            If ($ParentRGID) {
                $FilterXMLElement = $SOAPReq.Envelope.Body.listResourceGroupParameters.AppendChild($SOAPReq.CreateElement('filter'))
                $RGRelationXMLElement = $FilterXMLElement.AppendChild($SOAPReq.CreateElement('RGrelation'))
                $RGRelationshipXMLElement = $RGRelationXMLElement.AppendChild($SOAPReq.CreateElement('relationship'))
                $NULL = $RGRelationshipXMLElement.AppendChild($SOAPReq.CreateTextNode('all-children'))
                $RGIDXMLElement = $RGRelationXMLElement.AppendChild($SOAPReq.CreateElement('RGID'))
                $NULL = $RGIDXMLElement.AppendChild($SOAPReq.CreateTextNode($ParentRGID))
            }

            $SOAPFQDN = "https://$Global:EPControllerFQDN/telchemywebservices/services/telchemyRsrcGroupMgmtService"
            Write-Verbose $SOAPFQDN
            Write-Verbose $SOAPReq.OuterXML

            If ($Global:EPC_UseSOAPHeader) {
                $Headers = @{'SOAPAction' = 'urn:telchemyRsrcGroupMgmt/listResourceGroupParameters'}
            } Else {
                $Headers = @{}
            }
            
            [xml]$XMLResponse = (Invoke-WebRequest -UseBasicParsing -Method POST -URI $SOAPFQDN -Headers $Headers -Body $SOAPReq -ContentType 'text/xml').Content
            $ResourceGroupResults = $XMLResponse.Envelope.Body.listResourceGroupResults

            If ($ResourceGroupResults.result -eq 'success') {
                [psobject]$ResourceGroups = $ResourceGroupResults.ResourceGroupList.RG | ConvertFrom-XMLElement
                Return $ResourceGroups
            }
            Else {
                Throw $ResourceGroupResults.result
            }
        }
    }
}



Function Get-EPCControllerUUID {
    [cmdletbinding()]
    Param (
        [switch]$UseXML
    )
    
    Begin {
        Get-EPCWebSessionCookie
        $ProgressPreference = 'SilentlyContinue'
    }
    Process {
        $FQDN = "https://$Global:EPControllerFQDN/components.do?action=4&type=3"
        $Result = Invoke-RestMethod -Method GET -Uri $FQDN -WebSession $Global:EPCSessionCookie
        
        $ControllerUUID = $Result.data.uuid
                
        If ($ControllerUUID) {
            Return $ControllerUUID
        }
        Else {
            Write-Error "Could not obtain controller UUID"
        }
    }
}



Function Get-EPCBulkExportJobs {
    <#
        .SYNOPSIS
        Return list of EPC bulk export jobs
         
        .DESCRIPTION
        Return list of EPC bulk export jobs
         
        .EXAMPLE
        Get-EPCBulkExportJobs
        Returns a list of all EPC bulk export jobs
 
        .NOTES
        Version 1.0
    #>

    
    [cmdletbinding()]
    Param (
        [switch]$UseXML
    )
    
    Begin {
        Connect-EPCController
        
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCCred = New-Object -TypeName EPC.BulkExport.CredentialsType
            $EPCCred.username = $Global:EPControllerCred.UserName
            $EPCCred.password = $Global:EPControllerCred.GetNetworkCredential().Password
        }
        Else {
            #$ProgressPreference = 'SilentlyContinue'
        }
    }
    Process {
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCListExportJobsParams = New-Object -TypeName EPC.BulkExport.ListExportJobsType
            $EPCListExportJobsParams.credentials = $EPCCred
            
            $ExportJobResults = $Global:EPCWSDL_BulkExport.listExportJobs($EPCListExportJobsParams)
            Write-Verbose $ExportJobResults.result
            
            If ($ExportJobResults.result -eq 'success') {
                Return $ExportJobResults.jobList
            }
            Else {
                Throw $ExportJobResults.result
            }            
        }
        Else {
            [xml]$SOAPReq = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
                xmlns:urn='urn:telchemyBulkExport'>
                 <soapenv:Header/>
                 <soapenv:Body>
                 <urn:listExportJobsParameters>
                <credentials>
                <username>$($Global:EPControllerCred.UserName)</username>
                <password>$PwdEscaped</password>
                </credentials>
                 </urn:listExportJobsParameters>
                 </soapenv:Body>
                </soapenv:Envelope>"

            
            $SOAPFQDN = "https://$Global:EPControllerFQDN/telchemywebservices/services/telchemyBulkExportService"
            Write-Verbose $SOAPFQDN
            Write-Verbose $SOAPReq.OuterXML

            If ($Global:EPC_UseSOAPHeader) {
                $Headers = @{'SOAPAction' = 'urn:telchemyBulkExport/listExportJobsParameters'}
            } Else {
                $Headers = @{}
            }
            
            [xml]$XMLResponse = (Invoke-WebRequest -UseBasicParsing -Method POST -URI $SOAPFQDN -Headers $Headers -Body $SOAPReq -ContentType 'text/xml').Content
            $ExportJobResults = $XMLResponse.Envelope.Body.listExportJobsResults
            
            If ($ExportJobResults.result -eq 'success') {
                #[psobject]$JobList = $ExportJobResults.jobList.job | ConvertFrom-XMLElement
                Return $ExportJobResults.jobList.job
            }
            Else {
                Throw $ExportJobResults.result
            }    
        }
    }
}



Function Get-EPCBulkExportJobStatus {
    <#
        .SYNOPSIS
        Return the status of a given EPC bulk export job
         
        .DESCRIPTION
        Return the status of a given EPC bulk export job
         
        .PARAMETER JobID
        The JobID of the bulk export job to retrieve status
         
        .EXAMPLE
        Get-EPCBulkExportJobStatus -JobID 1
        Returns the export job status of bulk export job ID 1
 
        .NOTES
        Version 1.0
    #>

    
    [cmdletbinding()]
    Param (
        [Parameter(Mandatory=$True)]
        [int]$JobID,
        [switch]$UseXML
    )
    
    Begin {
        Connect-EPCController
        
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCCred = New-Object -TypeName EPC.SvcMgmt.CredentialsType
            $EPCCred.username = $Global:EPControllerCred.UserName
            $EPCCred.password = $Global:EPControllerCred.GetNetworkCredential().Password
        }
        Else {
            $ProgressPreference = 'SilentlyContinue'
        }
    }
    Process {
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCBulkExportStatusParams = New-Object -TypeName EPC.SvcMgmt.statusExportJobParameters>
            $EPCBulkExportStatusParams.credentials = $EPCCred
            
            $EPCBulkExportStatusParams.jobID = $JobID

            $ServiceResults = $Global:EPCWSDL_SvcMgmt.listServices($EPCListServicesParams)
            Write-Verbose $ServiceResults.result
            
            If ($ServiceResults.result -eq 'success') {
                Return $ServiceResults.ServiceList
            }
            Else {
                Throw $ServiceResults.result
            }            
        }
        Else {
            [xml]$SOAPReq = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
                xmlns:urn='urn:telchemySvcMgmt'>
                 <soapenv:Header/>
                 <soapenv:Body>
                 <urn:listServicesParameters>
                <credentials>
                <username>$($Global:EPControllerCred.UserName)</username>
                <password>$PwdEscaped</password>
                </credentials>
                 </urn:listServicesParameters>
                 </soapenv:Body>
                </soapenv:Envelope>"

            
            # Add the testpoint ID to the search if entered
            If ($ServiceClass) {
                $NewXMLElement = $SOAPReq.Envelope.Body.listServicesParameters.AppendChild($SOAPReq.CreateElement('serviceClass'))
                $NULL = $NewXMLElement.AppendChild($SOAPReq.CreateTextNode($ServiceClass.ToLower()))    
            }

            $SOAPFQDN = "https://$Global:EPControllerFQDN/telchemywebservices/services/telchemySvcMgmtService"
            Write-Verbose $SOAPFQDN
            Write-Verbose $SOAPReq.OuterXML

            If ($Global:EPC_UseSOAPHeader) {
                $Headers = @{'SOAPAction' = 'urn:telchemySvcMgmt/listServicesParameters'}
            } Else {
                $Headers = @{}
            }
            
            [xml]$XMLResponse = (Invoke-WebRequest -UseBasicParsing -Method POST -URI $SOAPFQDN -Headers $Headers -Body $SOAPReq -ContentType 'text/xml').Content
            $ServiceResults = $XMLResponse.Envelope.Body.listServicesResults
            
            If ($ServiceResults.result -eq 'success') {
                [psobject]$Services = $ServiceResults.ServiceList.service | ConvertFrom-XMLElement
                Return $Services
            }
            Else {
                Throw $ServiceResults.result
            }    
        }
    }
}



Function Get-EPCControllerPerfData {
    <#
        .SYNOPSIS
        Returns a list of performance metrics for a given EPC controller
         
        .DESCRIPTION
        Returns a list of performance metrics for a given EPC controller
 
        .PARAMETER ResultSize
        The number of results to return. Defaults to 1000.
         
        .EXAMPLE
        Get-EPCControllerPerfData
 
        .NOTES
        Version 1.0
    #>

    
    [cmdletbinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [Alias("testptID")]
        [string]$TestPointID,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [string]$TestPointName,
        [Parameter(Mandatory=$False)]
        [ValidateSet('LAST_HOUR','LAST_DAY','LAST_WEEK','LAST_MONTH','TODAY','YESTERDAY','WEEK_TO_NOW','MONTH_TO_NOW','CUSTOM', IgnoreCase=$True)]
        [string]$TimePeriod = 'LAST_DAY',
        [Parameter(Mandatory=$False)]
        [Alias("StartDateFrom")]
        [datetimeoffset]$TimePeriodFrom,
        [Parameter(Mandatory=$False)]
        [Alias("StartDateTo")]
        [datetimeoffset]$TimePeriodTo,        
        [Parameter(Mandatory=$False)]
        [ValidateSet('Reporter','Controller','Agent', IgnoreCase=$True)]
        [string]$AppType,        
        [Parameter(Mandatory=$False)]
        [string]$SortColumn = 'evt_date',        
        [Parameter(Mandatory=$False)]
        [int]$ResultSize = 1000
    )
    
    Begin {
        Get-EPCWebSessionCookie
        $ProgressPreference = 'SilentlyContinue'
    }
    Process {
        # Get the time period to return stats for
        Switch ($TimePeriod) {
            'LAST_HOUR' { $TimePeriodFrom = [DateTimeOffset]::Now.AddHours(-1); $TimePeriodTo = [DateTimeOffset]::Now }
            'LAST_DAY' { $TimePeriodFrom = [DateTimeOffset]::Now.AddDays(-1); $TimePeriodTo = [DateTimeOffset]::Now }
            'LAST_WEEK' { $TimePeriodFrom = [DateTimeOffset]::Now.AddDays(-7); $TimePeriodTo = [DateTimeOffset]::Now }
            'LAST_MONTH' { $TimePeriodFrom = [DateTimeOffset]::Now.AddMonths(-1); $TimePeriodTo = [DateTimeOffset]::Now }
        }
        
        If (!$TimePeriodTo) { $TimePeriodTo = [DateTimeOffset]::Now }
        
        $Body.Add('beginsecs', $TimePeriodFrom.ToUnixTimeSeconds())
        $Body.Add('endsecs', $TimePeriodTo.ToUnixTimeSeconds())
        
        # If Testpoint name/id not provided, assume we're getting controller stats
        If (!$TestPointID -and !$TestPointName) {
            # Get the UUID of the controller
            $FQDN = "https://$Global:EPControllerFQDN/components.do?action=4&type=3"
            $Result = Invoke-RestMethod -Method GET -Uri $FQDN -WebSession $Global:EPCSessionCookie
            $ControllerUUID = $Result.data.uuid

            # Get the database response time
        }
    }
}




Function Get-EPCLicense {
    <#
        .SYNOPSIS
        Returns a list of EPC licenses
         
        .DESCRIPTION
        Returns a list of EPC licenses
 
        .EXAMPLE
        Get-EPCLicense
 
        .NOTES
        Version 1.0
    #>

    
    [cmdletbinding()]
    Param (
        [switch]$UseXML
    )
    
    Begin {
        Get-EPCWebSessionCookie
        $Epoch = [datetime]"1970-01-01 00:00:00"
        $ProgressPreference = 'SilentlyContinue'
    }
    Process {
        $LicFQDN = "https://$Global:EPControllerFQDN/admin/licensecfg.do?action=12"
        $LicResult = Invoke-RestMethod -Method GET -Uri $LicFQDN -WebSession $Global:EPCSessionCookie

        $FormattedResults = $LicResult.pts | Select-Object `
                                            @{Name='Product';Expression={$_.product}},`
                                            @{Name='LicenseKey';Expression={$_.lk}},`
                                            @{Name='LastUpdate';Expression={$Epoch.AddSeconds($_.update).ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")}},`
                                            @{Name='Expiry';Expression={If ($_.expiry -gt 0) { $Epoch.AddSeconds($_.expiry).ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")}}},`
                                            status, host, id, `
                                            @{Name='AutoAssign';Expression={[regex]::Match($_.aV, 'autoAssign=(true|false)').captures.Groups[1].value }}
    }
    End {
        Return $FormattedResults
    }
}



Function Get-EPCLicenseDetails {
    <#
        .SYNOPSIS
        Returns details about a given EPC license
         
        .DESCRIPTION
        Returns details about a given EPC license. Accepts pipeline input from Get-EPCLicense
 
        .PARAMETER LicenseKey
        The license key of the license to retrieve
 
        .PARAMETER ID
        The id of the license to retrieve
         
        .EXAMPLE
        Get-EPCLicenseDetails -LicenseKey abcdef -ID 1
        Returns EPC license details about license key abcdef
 
        .EXAMPLE
        Get-EPCLicense | Where {$_.Product -like 'DVQ*'} | Get-EPCLicenseDetails
        Returns detailed license information about any license that starts with DVQ
 
        .NOTES
        Version 1.0
    #>

    
    [cmdletbinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$True)]
        [string]$LicenseKey,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$True)]
        [string]$ID,
        [switch]$UseXML
    )
    
    Begin {
        Get-EPCWebSessionCookie
        $ProgressPreference = 'SilentlyContinue'
        [System.Collections.ArrayList]$LicMembers = @()
        
    }
    Process {
        Write-Verbose "LicenseKey: $LicenseKey"
        Write-Verbose "ID: $ID"
        $LicFQDN = "https://$Global:EPControllerFQDN/admin/viewlic.htm?licensekey=$LicenseKey&lkeyid=$ID"

        If ($PSItem.AutoAssign) { $LicFQDN = $LicFQDN + "&autoAssign=$($PSItem.AutoAssign)" } # For whatever reason, the value of the AutoAssign parameter is passed to the next page via the first page.

        Write-Verbose $LicFQDN
        $LicResult = Invoke-WebRequest -UseBasicParsing -Method GET -Uri $LicFQDN -WebSession $Global:EPCSessionCookie        
        $Item = [PSCustomObject][Ordered]@{}

        # Parse out tables and focus on the table which contains all the data we want
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            Write-Verbose 'Using WSDL method'
            $Tables = $LicResult.ParsedHtml.body.getElementsByTagName('Table')
            $LicMemberRows = $Tables[0].rows | Select-Object InnerHTML # Get the row data innerHTML, which contains the data we want
        } Else { # PS v.6+ doesn't have ParsedHtml in Invoke-WebRequest, so we have to use different method
            $Tables = $LicResult.Content | ConvertFrom-Html
            $Tables = $Tables.SelectNodes("//table")
            $LicMemberRows = $Tables[0].SelectNodes("//tr")
        }

        $LicMemberRows = $LicMemberRows[1..($LicMemberRows.count - 2)] # Ignore the first row and the last 2 rows
        Write-Verbose "RowCount: $($LicMemberRows.Count)"
        
        # Parse each row and pull out the data which is in <TD></TD> blocks into a custom object
        ForEach ($Row in $LicMemberRows) {
            $RowData = $Row.InnerHTML
            $RowMatch = [regex]::Match($RowData, '^\s*<(TD|td) [\w=":;% ]+>([\w\ ]+)</(TD|td)>\s+<(TD|td)[\w=":;% ]*>([\w\s\-\.,<>:;&/]+)</(TD|td)>').captures
            $ItemName = $RowMatch.groups[2].value
            $ItemValue = $RowMatch.groups[5].value

            If ($ItemValue -eq ' ') { # If the item value is empty, it might be a date value provided via inline javascript. Try to get the value from there
                $RowMatchDate = [regex]::Match($RowData, 'var _(expire|update) = (\d+)').captures
                Try {
                    If ($NULL -ne $RowMatchDate) { 
                        $RowMatchDate = $RowMatchDate.groups[2].value
                        If ($RowMatchDate -gt 0) { 
                            $ItemValue = (([System.DateTimeOffset]::FromUnixTimeSeconds($RowMatchDate)).LocalDateTime).ToString("yyyy-MM-dd HH:mm:ss") 
                        } 
                    } 
                }
                Catch {
                    $ItemValue = ''
                }
            }

            $Item | Add-Member -NotePropertyName $ItemName -NotePropertyValue $ItemValue
        }
        $LicMembers += $Item
    }
    End {
        Return $LicMembers
    }
}




Function Get-EPCPoolKey {
    <#
        .SYNOPSIS
        Returns a list of EPC pool keys
         
        .DESCRIPTION
        Returns a list of EPC pool keys
 
        .PARAMETER PoolKeyType
        Return info about a certain type of pool key. Select from 'currentPoolKeys', 'newPoolKeys', 'retiredPoolKeys'. Defaults to 'currentPoolKeys'
 
        .EXAMPLE
        Get-EPCPoolKey
 
        .NOTES
        Version 1.0
    #>

    
    [cmdletbinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [ValidateSet('currentPoolKeys', 'newPoolKeys', 'retiredPoolKeys', IgnoreCase=$False)]
        [string]$PoolKeyType = 'currentPoolKeys'
    )
    
    Begin {
        Get-EPCWebSessionCookie
        $ProgressPreference = 'SilentlyContinue'
        $Epoch = [datetime]"1970-01-01 00:00:00"
    }
    Process {
        $FQDN = "https://$Global:EPControllerFQDN/poolKey.do?action=3&poolKeyType=$PoolKeyType"
        $Result = Invoke-RestMethod -Method GET -Uri $FQDN -WebSession $Global:EPCSessionCookie

        $FormattedResults = $Result.pts | Select-Object `
                                            name,`
                                            @{Name='resourceGroup';Expression={$_.resoureGroup}},`
                                            roles, description, type, autoAssign,`
                                            @{Name='used';Expression={($_.pkUsages -split '\s*/\s*')[0]}},`
                                            @{Name='total';Expression={($_.pkUsages -split '\s*/\s*')[1]}},`
                                            @{Name='dateCreated';Expression={$Epoch.AddMilliseconds($_.dateCreated).ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")}},`
                                            @{Name='dateExpired';Expression={If ($_.dateExpired -gt 0) {$Epoch.AddMilliseconds($_.dateExpired).ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")}}}
    }
    End {
        Return $FormattedResults
    }
}