CitrixCCILabTools.psm1

function Repair-CitrixGETLABFile {
  <#
  .Synopsis
    Fixes the GET LAB ica file when requesting to takeover a student Citrix lab
  .DESCRIPTION
    Citrix creates ICA files to help trainers take over student labs, the ICA file, in its default state
    does not work and therefore needs to be edited. This command changes the last ICA file downloaded to
    the corrent format so that Citrix trainers can take over student labs easily.
  .EXAMPLE
    Repair-CitrixGETLABFile
    This will find the latest ICA file in the users downloads folder and modify it to the correct format
  .EXAMPLE
    Repair-CitrixGETLABFile -DownloadPath c:\users\BrentD09\Documents
    This will find the latest ICA file in the Documents folder and modify it to the correct format
  .PARAMETER DownloadPath
    This tells the command where to look for the downloaded ICA files
  .NOTES
    Created by: Brent Denny
    Created on: 14 Nov 2019
  #>

  [cmdletbinding()]
  Param (
    $DownloadPath = '~\downloads'
  )
  $DownloadPath = $DownloadPath -replace '^(.*)\\{1,}$','$1'
  if (Test-Path $DownloadPath\*.ICA) {
    $LatestICAfile = Get-ChildItem $DownloadPath\*.ICA | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 1
    $LatestICAfileContent =  Get-Content $LatestICAfile
    if ($LatestICAfileContent.contains('Domain=studentdesktop')) {
      $FixedFileName = $LatestICAfile.FullName -replace '.ica$','FIXED.ica' -replace '\s+',''
      (get-content $LatestICAfile.FullName) -replace '\=studentdesktop','=WORKSPACELAB' | Out-File -Encoding utf8 -Force -FilePath $FixedFileName
      if (Test-Path -Path 'C:\Program Files (x86)\Citrix\ICA Client\wfcrun32.exe') {
        start-process -FilePath 'C:\Program Files (x86)\Citrix\ICA Client\wfcrun32.exe' -ArgumentList $FixedFileName
      }
      else {Write-Warning 'Could not find the ICA client wfcrun32.exe, Please make sure you have Receiver or WorkspaceApp installed '}
    }
    else {Write-Warning 'There was nothing to fix in the ICA file, the latest ICA file withing the download directory appears to be correctly configured'}
  }
  else {Write-Warning 'Cannot locate any ICA files in the download path, try re-running the command like this: Repair-CitrixGETLABFile -DownloadPath <Path where your ica file is located>'}
}