functions/Get/Get-CustomerConfig.ps1

function Get-CustomerConfig {
    <#
    .SYNOPSIS
        This function retrieves the specified configuration value from default or given customer config file.
 
    .DESCRIPTION
        This function retrieves the specified configuration value from default or given customer config file.
 
    .PARAMETER XPath
        Xpath to configuration you want to return
 
    .PARAMETER ConfigFilePath
        Path to customer configuration file.
 
    .EXAMPLE
        PS C:\> Get-CustomerConfig -Xpath "//credential[@name='GithubPAT']"
    #>


    param(
        [Parameter(Mandatory = $true)]
        [string]$XPath,
        [Parameter(Mandatory = $false)]
        [string]$ConfigFilePath = 'C:\inetpub\approot\_Install\_Tools\customer.config'
    )

    begin { 
        if (-not (Test-Path $ConfigFilePath)) {
            $ConfigFilePath = 'C:\inetpub\approot\_Install\_Tools\customer.config'
            New-Item -Path $ConfigFilePath -Force | Out-Null

            $configTemplate = @'
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <credentials>
        <credential name="GithubPAT" value="{0}" />
    </credentials>
    <github>
        <branch name="defaulBranch" value="master" />
    </github>
</configuration>
'@


            do { 
                $token = Read-Host 'Enter Github Personal Access Token(PAT)'
                $token = $token.Trim()
            }
            while ([string]::IsNullOrEmpty($token) -or $token.Length -lt 10)

            Set-Content -Path $ConfigFilePath -Value ($configTemplate -f $token)
        }
    }
    process { 
        [xml]$config = Get-Content $ConfigFilePath
        $config | Select-XML -XPath $XPath | Select-Object -ExpandProperty Node | Select-Object -ExpandProperty Value
    }
}