src/functions/Get-CrmConnectionString.ps1

function Get-CrmConnectionString {
  <#
  .SYNOPSIS
  Convenience function for building the CRM Connection string for Regent's systems.
   
  .DESCRIPTION
  A simple switch statement to build the CRM Connection string. The values are hard-coded, so if any of the details change, they'll need to be updated here.
 
  .PARAMETER CrmInstance
   
  #>

  param(
    #The unique CRM Instance name.
    [ValidateSet("CRMRECRUIT", "CRMRECRUITTEST", "CRMADVISE", "CRMADVISETEST")]
    [Parameter(Mandatory = $true)]
    $CrmInstance,

    # Add this switch to just return the organization url of the CRM, without the AuthType appended (used in conjunction with REST API functions)
    [switch]$UrlOnly

  )
    
  switch ($CrmInstance) { 
    "CRMRECRUIT" {$url = "https://recruitercrm2.regent.edu/CRMRECRUIT"} 
    "CRMRECRUITTEST" {$url = "https://rctrdevcrm.regent.edu/CRMRECRUITTEST"} 
    "CRMADVISE" {$url = "https://advisecrm.regent.edu/CRMADVISE"} 
    "CRMADVISETEST" {$url = "https://advisedevcrm.regent.edu/CRMADVISETEST"} 
    default { throw "Invalid CRM Instance specified"}
  }

  if ($UrlOnly) {
    return $url 
  }
  else { 
    $conn = "AuthType=AD;Url=$url;"
    Write-Verbose "Crm Connection String: $conn"
    return $conn
  }
}