################################################################################ # Unload_RobotJobLogsByDate.ps1 # ============================================================================== # # User Story # ---------- # "For specific robot, I want to list [and save] all jobs and their logs for specific date" # # To run script: - # 1) Use file explorer to find .ps1 directory # 2) Enter cmd on address bar [to open command window] # 3) At prompt enter # > powershell # 4) At prompt enter # > .\.ps1 # # Date Initials Comment # ----------- -------- ---------------------------------------------------- # 07-Apr-2022 MOB Initial creation ################################################################################ #=============================================================================== # E N V I R O N M E N T D I V I S I O N #=============================================================================== #------------------------------------------------------------------------------- # R U N T I M E P A R A M E T E R s [ D E F A U L T ] #------------------------------------------------------------------------------- Param ( [string] $tenancyName = "", [string] $username = "", [string] $password = "", [string] $orchestratorURL = "", [bool] $windowsAuth = $false ) #=============================================================================== # D A T A D I V I S I O N #=============================================================================== [string]$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path #------------------------------------------------------------------------------- # F I L E C O N T R O L #------------------------------------------------------------------------------- [string]$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path [string]$logFilename = "$scriptPath\Output\Unload_RobotJobLogs.log" [string]$csvFolderRobotNamesFilename = "$scriptPath\Input\FolderRobotNames.csv" [string]$csvFolderRobotJobsDetailsFilename = "$scriptPath\Output\FolderRobotJobsDetails.csv" [string]$csvFolderRobotJobLogsFilenameRump = "$scriptPath\Output\RobotJobLogs" #------------------------------------------------------------------------------- # W O R K I N G S T O R A G E [ G L O B A L V A R I A B L E S ] #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # C O M M O N / U T I L I T Y C O N S T A N T S #------------------------------------------------------------------------------- New-Variable -Name Seperator -Value "".PadRight(125,"-") -Option ReadOnly -Scope Global -Force # Separator - used for on-screen'reporting/logging' New-Variable -Name delimeter -value "|" -Option ReadOnly -Scope Global -Force New-Variable -Name folderColour -value "Green" -Option ReadOnly -Scope Global -Force New-Variable -Name QueuesColour -value "Yellow" -Option ReadOnly -Scope Global -Force New-Variable -Name robotColour -value "Cyan" -Option ReadOnly -Scope Global -Force New-Variable -Name triggerColour -value "Yellow" -Option ReadOnly -Scope Global -Force New-Variable -Name machineColour -value "Green" -Option ReadOnly -Scope Global -Force New-Variable -Name credentialColour -value "Green" -Option ReadOnly -Scope Global -Force New-Variable -Name exceptionColour -value "Red" -Option ReadOnly -Scope Global -Force New-Variable -Name badColour -value "Red" -Option ReadOnly -Scope Global -Force New-Variable -Name goodColour -value "Green" -Option ReadOnly -Scope Global -Force New-Variable -Name infoColour -value "White" -Option ReadOnly -Scope Global -Force New-Variable -Name queueColour -value "Green" -Option ReadOnly -Scope Global -Force New-Variable -Name extractColour -value "Yellow" -Option ReadOnly -Scope Global -Force New-Variable -Name YellowColor -value "Yellow" -Option ReadOnly -Scope Global -Force New-Variable -Name DarkYellowColor -value "DarkYellow" -Option ReadOnly -Scope Global -Force New-Variable -Name CyanColor -value "Cyan" -Option ReadOnly -Scope Global -Force New-Variable -Name contentType -Value "application/json;charset=utf-8" -Option ReadOnly -Scope Global -Force New-Variable -Name warningColour -value "Yellow" -Option ReadOnly -Scope Global -Force #------------------------------------------------------------------------------- # A R R A Y S #------------------------------------------------------------------------------- $folderNameArray = @{} # key = folder id, value = folder name $folderIdArray = @{} # key = folder name, value = folder id $folderRobotsNameArray = @{} # key = folder id, value = robot array [robotId/robotName] $folderRobotsIdArray = @{} # key = folder id, value = robot array [robotId/robotName] $robotIdtoNameArray = @{} # key = robot id, value = robot name $robotIdtoNameExtractArray = @{} # key = robot id, value = robot name $jobStartDateArray = @{} # key = robot id, value = start date for jobs/logs $jobEndDateArray = @{} # key = robot id, value = end date for jobs/logs #------------------------------------------------------------------------------- # R U N T I M E P A R A M E T E R s [ I N P U T ] #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # O D D S A N D S O D S #------------------------------------------------------------------------------- $defaultStartOfLogsExtractPeriod = [datetime] $defaultEndOfLogsExtractPeriod = [datetime] #------------------------------------------------------------------------------- # F L A G S #------------------------------------------------------------------------------- #=============================================================================== # P R O C E D U R E D I V I S I O N #=============================================================================== #------------------------------------------------------------------------------- # U T I L I T Y F U N C T I O N S #------------------------------------------------------------------------------- function x-write-log { Param ($message, [string] $color) $now = Get-Date -Format "G" $line = "$now`t$message" $line | Add-Content $logFilename -Encoding UTF8 if ($color) { Write-Host $line -ForegroundColor $color } else { Write-Host $line } } #------------------------------------------------------------------------------- function x-create-filename ($filepath) { [string]$directory = [System.IO.Path]::GetDirectoryName($filePath); [string]$strippedFileName = [System.IO.Path]::GetFileNameWithoutExtension($filePath); [string]$extension = [System.IO.Path]::GetExtension($filePath); [string]$newFileName = [DateTime]::Now.ToString("yyyyMMdd-HHmmss") + " " + $tenancyName + " " + $strippedFileName + $extension; [string]$newFilePath = [System.IO.Path]::Combine($directory, $newFileName); return $newFilePath } #------------------------------------------------------------------------------- function X-FormatDateTime ($timeStamp) { $unformattedDate = [datetime]$timeStamp $formattedDate = $unformattedDate.ToString("dd/MM/yyyy HH:mm:ss.fff") return $formattedDate } #------------------------------------------------------------------------------- function X-FormatDateTime-for-orchestrator ($timeStamp) { $unformattedDate = [datetime]$timeStamp $formattedDate = $unformattedDate.ToString("yyyyMMddTHH:mm:ssZ") return $formattedDate } #------------------------------------------------------------------------------- function X-Get-ObjectMember { [CmdletBinding()] Param( [Parameter(Mandatory=$True, ValueFromPipeline=$True)] [PSCustomObject]$obj ) $obj | Get-Member -MemberType NoteProperty | ForEach-Object { $key = $_.Name [PSCustomObject]@{Key = $key; Value = $obj."$key"} } } #------------------------------------------------------------------------------- function x-Show-Colors( ) { $colors = [Enum]::GetValues( [ConsoleColor] ) $max = ($colors | foreach { "$_ ".Length } | Measure-Object -Maximum).Maximum foreach( $color in $colors ) { Write-Host (" {0,2} {1,$max} " -f [int]$color,$color) -NoNewline Write-Host "$color" -Foreground $color } } #------------------------------------------------------------------------------- function x-Show-Colors-On-Colors( ) { $colors = [enum]::GetValues([System.ConsoleColor]) Foreach ($bgcolor in $colors){ Foreach ($fgcolor in $colors) { Write-Host "$fgcolor|" -ForegroundColor $fgcolor -BackgroundColor $bgcolor -NoNewLine } Write-Host " on $bgcolor" } } #------------------------------------------------------------------------------- function x-invoke-restmethod-get ( $uri, $folderId ) { $errorDetails = "" $result = "" $reconnnectCount = 0 while ($true) { try { if ( $folderId ) { $headerUnit = $GETheaders + @{"X-UIPATH-OrganizationUnitId"=$folderId} } else { $headerUnit = $GETheaders } $result = Invoke-RestMethod -Uri $uri -Method Get -ContentType $contentType -Headers $headerUnit -UseDefaultCredentials:$windowsAuth break } catch { $errorDetails = $_.ErrorDetails $JSONstring = $errorDetails.Message $vPSObject = $JSONstring | ConvertFrom-Json x-write-log ("x-invoke-restmethod-get Error: $($vPSObject[0].message)") -color $exceptionColour x-write-log ("uri : $($uri)") -color $exceptionColour if ( $vPSObject[0].message -eq "You are not authenticated!" ) { $reconnectCount = $reconnectCount + 1 if ( $reconnectCount -le 4 ) { x-write-log "Sleep for 10 seconds then try to re-connect to Orchestrator..." Start-sleep -Seconds 10 x-connect-to-orchestrator } else { x-write-log "Error on Invoke-RestMethod - exiting program" z-exit } } else { break } } x-write-log "" } return $result } #------------------------------------------------------------------------------- function x-connect-to-orchestrator ( ) { x-write-log "X Connecting to Orchestrator... $($orchestratorURL)" -color $infoColour $global:POSTheaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $global:POSTheaders.Add("Content-Type", "application/json") $global:POSTbody = "{ `n`"tenancyName`": `"$tenancyName`", `n`"usernameOrEmailAddress`": `"$username`", `n`"password`": `"$password`" `n} `n" $global:POSTresponse = Invoke-RestMethod "$($orchestratorURL)/api/Account/Authenticate" -Method 'POST' -Headers $POSTheaders -Body $POSTbody # Login success or fail if ($global:POSTresponse.result) { x-write-log "`tOrchestrator Login success" x-write-log "" $global:BearerToken = $POSTresponse.result $global:GETheaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $global:GETheaders.Add("Content-Type", "application/json") $global:GETheaders.Add("Authorization", "Bearer $BearerToken") $global:GETheaders.Add("X-UIPATH-TenantName", "$tenancyName") } else { x-write-log "`tERROR: Orchestrator Login failed 1" -color $exceptionColour x-write-log "`t`tInput parameter file does not detail valid Orchestrator URL --> $orchestratorURL" -color "Red" x-write-log "`t`tOR invalid username/password --> ??" -color $exceptionColour exit 1 } } #------------------------------------------------------------------------------- # P R O G R A M 'F U N C T I O N S' [AKA COBOL SECTIONS] #------------------------------------------------------------------------------- function x-fetch-folder-robot-jobs ( $folderName, $folderId, $robotName, $robotId ) { if ( $jobStartDateArray[$robotId] -eq $null -or $jobStartDateArray[$robotId] -eq "" ) { $jobStartDateArray[$robotId] = $defaultStartOfLogsExtractPeriod } if ( $jobEndDateArray[$robotId] -eq $null -or $jobEndDateArray[$robotId] -eq "" ) { $jobEndDateArray[$robotId] = $defaultEndOfLogsExtractPeriod } $startDate = $jobStartDateArray[$robotId] $endDate = $jobEndDateArray[$robotId] x-write-log "`t`t`t`tStart date/time : $($startDate.ToString('yyyy-MM-ddT00:00:00.000Z'))" x-write-log "`t`t`t`tEnd date/time : $($EndDate.ToString('yyyy-MM-ddT23:59:59.999Z'))" #------------------------------------------------------------------------------- # Set up output file for Robot Logs $csvFolderRobotJobLogsFilename = "$scriptPath\Output\$($folderName) $($robotName) $($startDate.ToString('yyyy-MM-dd')) to $($endDate.ToString('yyyy-MM-dd')) JobLogs.csv" $csvFolderRobotJobLogsFilename = x-create-filename $csvFolderRobotJobLogsFilename try { $uriJobs = "$orchestratorURL/odata/Jobs?`$filter=Robot/Id eq $($robotId) and StartTime gt $($startDate.ToString('yyyy-MM-ddT00:00:00.000Z')) and StartTime lt $($EndDate.ToString('yyyy-MM-ddT23:59:59.999Z'))&`$orderby=StartTime asc" $resJobs = x-invoke-restmethod-get $uriJobs $folderId } catch { x-write-log "`t`t`t`t`tError on Jobs Fetch for robot/id : $($robotName) [$($robotid)]"} if ( $resJobs.value ) { $resJobs.value | foreach { [datetime]$startTime = $_.StartTime # # If job is still running then $_.EndTime will be empty # if ( $_.EndTime ) { [datetime]$endTime = $_.EndTime $duration = $endTime - $startTime $durationTotalSeconds = $duration.TotalSeconds.ToString("N02") $durationTotalMinutes = $duration.TotalMinutes.ToString("N02") } else { $durationTotalSeconds = "TBD" $durationTotalMinutes = "TBD" } $myHashtable = [ordered]@{ FolderName = $folderName RobotName = $robotName Key = $_.Key StartTime = $_.StartTime EndTime = $_.EndTime durationTotalSeconds = $durationTotalSeconds durationTotalMinutes = $durationTotalMinutes State = $_.State Source = $_.Source SourceType = $_.SourceType BatchExecutionKey = $_.BatchExecutionKey Info = $_.Info CreationTime = $_.CreationTime StartingScheduleId = $_.StartingScheduleId ReleaseName = $_.ReleaseName Type = $_.Type InputArguments = $_.InputArguments OutputArguments = $_.OutputArguments HostMachineName = $_.HostMachineName HasMediaRecorded = $_.HasMediaRecorded PersistenceId = $_.PersistenceId ResumeVersion = $_.ResumeVersion StopStrategy = $_.StopStrategy ReleaseVersionId = $_.ReleaseVersionId Id = $_.Id } $myObject = [pscustomobject]$myHashtable $myObject | Export-csv $global:csvFolderRobotJobsDetailsFilename -encoding "UTF8" -NoTypeInformation -Append # # For the Job just extracted - get all logs!!! # $jobKey = $_.Key $skipCount = 0 $skipRecords = $skipCount * 10000 $resJobLogsCount = 10000 # # Lets start search just before midnight # $timeStamp = ([DateTime]$startDate).AddMilliseconds(-1) while ( $resJobLogsCount -eq 10000 ) { if ( $skipCount -eq 0 ) { x-write-log "`t`t`t`tFetching logs for JobKey: $($JobKey)" } else { x-write-log "`t`t`t`tFetching next 10000 logs for JobKey: $($JobKey)" } $resJobLogs = $null $resJobLogsCount = 0 $uriJobLogs = "$orchestratorURL/odata/RobotLogs?`$filter=JobKey eq $($jobKey) and TimeStamp gt $($timeStamp.ToString('yyyy-MM-ddTHH:mm:ss.fffZ'))&`$orderby=TimeStamp asc&`$top=10000&`$count=true" x-write-log "`t`t`t`t`tOrchestrator URI: $($uriJobLogs)" $resJobLogs = x-invoke-restmethod-get $uriJobLogs $folderId if ( $resJobLogs.value ) { $resJobLogs.value | foreach { try { $rawMessageJSON = ($_.RawMessage | ConvertTo-Json -Compress).Replace('"', '""') } catch { x-write-log "`t`t`t`t`tError on RawMessage : $($_.RawMessage)" } $myHashtable = [ordered]@{ TimeUniversal = ([DateTime]$_.TimeStamp).ToUniversalTime() TimeLocal = ([DateTime]$_.TimeStamp).ToLocalTime() Level = $_.Level Robot = $_.RobotName Process = $_.ProcessName User = $_.WindowsIdentity Message = $_.Message TimeStampUTC = $_.TimeStamp FolderName = $folderName JobKey = $_.JobKey RawMessage = $rawMessageJSON MachineId = $_.MachineId Id = $_.Id } $myObject = [pscustomobject]$myHashtable $myObject | Export-csv $csvFolderRobotJobLogsFilename -encoding "UTF8" -NoTypeInformation -Append $timeStamp = [DateTime]$_.TimeStamp } $resJobLogsCount = $resJobLogs.'@odata.count' } $skipCount = $skipCount + 1 } } } } #------------------------------------------------------------------------------- function aa-fetch-folders ( ) { x-write-log "AA Fetch Folders" -color $infoColour try { ## Get all Folders $uriFolders = "$orchestratorURL/odata/Folders" $resFolders = x-invoke-restmethod-get $uriFolders if ($resFolders.value) { $resFolders.value | sort FullyQualifiedName | foreach { $folderId = $_.Id $folderName = $_.FullyQualifiedName $folderNameArray[$folderId] = $folderName $folderIdArray[$folderName] = $folderId } } } catch { } # # List folders Stores # #x-write-log "`tListing folders in ascending order" -color $folderColour #$folderNameArray.GetEnumerator() | # Sort-Object { $_.Value } | # ForEach-Object { x-write-log "`t`t$($_.Value)" } # x-write-log "" } #------------------------------------------------------------------------------- function ab-fetch-folders-robots ( ) { x-write-log "AB Fetch Folders Robots" -color $infoColour # # Note - Robot name is NOT unique across folders # # Build a fold=er array that contains an array of robot ids/name # # $folderRobotArray[$folderName] = robot id/name array # $folderNameArray.GetEnumerator() | Sort-Object { $_.Value } | ForEach-Object { $folderId = $_.key $folderName = $_.value x-write-log "`t$($folderName) (Id = $($folderId))" -color $folderColour try { $uriSessions = "$orchestratorURL/odata/Sessions?`$expand=Robot(`$expand=License)" $resSessions = x-invoke-restmethod-get $uriSessions $folderId if ($resSessions.value) { $robotNameArray = @{} $robotIdArray = @{} $resSessions.value | foreach { # Robot $_.Robot | foreach { $robotId = $_.Id $robotName = $_.Name $robotNameArray[$robotId] = $robotName $robotIDArray[$robotName] = $robotId # Capture ALL robot ids and robot names $robotIdtoNameArray[$robotId] = $robotName } } $folderRobotsNameArray[$folderId] = $robotNameArray $folderRobotsIdArray[$folderId] = $robotIdArray } } catch {} #x-write-log "" } # # List folders robots [in ascending order] # <# x-write-log "Listing folders in ascending order" -color $infoColour $folderNameArray.GetEnumerator() | Sort-Object { $_.Value } | ForEach-Object { $folderId = $_.key $folderName = $_.value x-write-log "`t$($folderName) (Id = $($folderId))" -color $folderColour try { $robotNameArray = $folderRobotsNameArray[$folderId] $robotNameArray.GetEnumerator() | Sort-Object { $_.Value } | ForEach-Object { $robotId = $_.Name $robotName = $_.value x-write-log "`t`t$($robotName) (Id = $($robotId))" -color $robotColour } } catch { x-write-log "`t`tNo robots found" } x-write-log "" } #> } #------------------------------------------------------------------------------- function a-start ( ) { #------------------------------------------------------------------------------- # Set up output files i.e.create unique names $global:logFilename = x-create-filename $global:logFilename $global:csvFolderRobotJobsDetailsFilename = x-create-filename $global:csvFolderRobotJobsDetailsFilename x-write-log "A Starting..." -color $infoColour #------------------------------------------------------------------------------- # Determine/format date 7 days ago $date = (Get-Date).AddDays(-1) $global:year = $date.ToString('yyyy') $global:month = $date.ToString('MM') $global:day = $date.ToString('dd') $global:defaultStartOfLogsExtractPeriod = Get-Date -Year $year -Month $month -Day $day -Hour 0 -Minute 0 -Second 0 -Millisecond 0 $date = (Get-Date) $global:year = $date.ToString('yyyy') $global:month = $date.ToString('MM') $global:day = $date.ToString('dd') $global:defaultEndOfLogsExtractPeriod = Get-Date -Year $year -Month $month -Day $day -Hour 23 -Minute 59 -Second 59 -Millisecond 0 #------------------------------------------------------------------------------- # Connect to orchestrator [using fetched Orchestrator URL] x-connect-to-orchestrator #------------------------------------------------------------------------------- # Fetch Orchestrator 'object' details aa-fetch-folders ab-fetch-folders-robots } #------------------------------------------------------------------------------- function ba-process-folders-robots ( ) { x-write-log "BA Processing folders and robots in ascending order" -color $infoColour $folderNameArray.GetEnumerator() | Sort-Object { [string]$_.Value } | ForEach-Object { $folderId = $_.Name $folderName = $_.Value x-write-log "`t$($folderName) (Id = $($folderId))" -color $folderColour if ( $folderRobotsNameArray[$folderId] ) { try { $robotNameArray = $folderRobotsNameArray[$folderId] $robotNameArray.GetEnumerator() | Sort-Object { $_.Value } | ForEach-Object { $robotId = $_.Name $robotName = $_.value if ($robotIdtoNameExtractArray[$robotId]) { x-write-log "`t`t$($robotName) (Id = $($robotId))" -color $robotColour x-write-log "`t`t`tExtracting jobs and associated logs" x-fetch-folder-robot-jobs $folderName $folderId $robotName $robotId } } } catch { $errorException = $_.Exception $errorScriptTraceBack = $_.ScriptTraceBack x-write-log ("ba-process-folders-robots: $($errorException)") -color $exceptionColour x-write-log ("robotId : $($robotId)") -color $exceptionColour x-write-log ("robotName : $($robotName)") -color $exceptionColour x-write-log ("ScriptTraceBack : ") -color $exceptionColour x-write-log ("$($errorScriptTraceBack)") -color $exceptionColour } } x-write-log "" } } #------------------------------------------------------------------------------- function b-main ( ) { x-write-log "B Main" -color $infoColour $fileExists = $false $fileExists = Test-Path -Path $global:csvFolderRobotNamesFilename -PathType Leaf if ( $fileExists ) { x-write-log "`tPROCESSING ROBOTS FROM FILE $($global:csvFolderRobotNamesFilename)" -color $infoColour Import-Csv $global:csvFolderRobotNamesFilename | Sort-Object { $_.FolderName, $_.RobotName } | ForEach-Object { #x-write-log "`tFrom file [sorted] $($_.FolderName) / $($_.RobotName)" # # Validate folder/robot name pairs on file # $folderName = $_.FolderName $robotName = $_.RobotName $startDate = $_.StartDate $endDate = $_.EndDate if ( $folderIdArray[$_.FolderName] ) { $folderId = $folderIdArray[$_.FolderName] $folderName = $_.FolderName $robotName = $_.RobotName $robotNameArray = $folderRobotsNameArray[$folderId] $robotIdArray = $folderRobotsIdArray[$folderId] # # If we have ONLY folder name listed then run for all BOTs in folder # if ( $robotName -eq $null -or $robotName -eq "" ) { $robotIdArray.GetEnumerator() | ForEach-Object { $robotName = $_.Name $robotId = $robotIdArray[$robotName] $robotIdtoNameExtractArray[$robotIdArray[$robotName]] = $robotName if ( $startDate -eq $null -or $startDate -eq "" ) { $jobstartDateArray[$robotId] = $global:defaultStartOfLogsExtractPeriod } else { try { $startDateTime = [Datetime]::ParseExact($startDate, 'dd/MM/yyyy', $null) $jobStartDateArray[$robotId] = $startDateTime } catch { $jobStartDateArray[$robotId] = $global:defaultStartOfLogsExtractPeriod } } if ( $endDate -eq $null -or $endDate -eq "" ) { $jobEndDateArray[$robotId] = $global:defaultEndOfLogsExtractPeriod } else { try { $endDateTime = [Datetime]::ParseExact($endDate, 'dd/MM/yyyy', $null) $jobEndDateArray[$robotId] = $endDateTime } catch { $jobEndDateArray[$robotId] = $global:defaultEndOfLogsExtractPeriod } } } } else { if ( $robotIdArray[$robotName] ) { $robotId = $robotIdArray[$robotName] $robotIdtoNameExtractArray[$robotIdArray[$robotName]] = $robotName if ( $startDate -eq $null -or $startDate -eq "" ) { $jobstartDateArray[$robotId] = $global:defaultStartOfLogsExtractPeriod } else { try { $startDatetime = [Datetime]::ParseExact($startDate, 'dd/MM/yyyy', $null) $jobStartDateArray[$robotId] = $startDateTime } catch { $jobStartDateArray[$robotId] = $global:defaultStartOfLogsExtractPeriod } } if ( $endDate -eq $null -or $endDate -eq "" ) { $jobEndDateArray[$robotId] = $global:defaultEndOfLogsExtractPeriod } else { try { $endDateTime = [Datetime]::ParseExact($endDate, 'dd/MM/yyyy', $null) $jobEndDateArray[$robotId] = $endDateTime } catch { $jobEndDateArray[$robotId] = $global:defaultEndOfLogsExtractPeriod } } } else { x-write-log "`t$($folderName) / $($robotName) - Unknown robot - skipping" -color $exceptionColour } } } else { x-write-log "`t$($folderName) / $($robotName) - Unknown folder - skipping" -color $exceptionColour } } } else { x-write-log "`tPROCESSING ALL ROBOTS" -color $infoColour $robotIdtoNameExtractArray = $robotIdtoNameArray # key = robotId, value = robotName } x-write-log "" ba-process-folders-robots } #------------------------------------------------------------------------------- function z-exit ( ) { x-write-log "Z ...exiting" -color $infoColour Remove-Variable -Name badColour -Scope Global -Force Remove-Variable -Name BearerToken -Scope Global -Force Remove-Variable -Name contentType -Scope Global -Force Remove-Variable -Name credentialColour -Scope Global -Force Remove-Variable -Name csvFolderRobotJobsDetailsFilename -Scope Global -Force Remove-Variable -Name csvFolderRobotNamesFilename -Scope Global -Force Remove-Variable -Name CyanColor -Scope Global -Force Remove-Variable -Name DarkYellowColor -Scope Global -Force Remove-Variable -Name day -Scope Global -Force Remove-Variable -Name defaultEndOfLogsExtractPeriod -Scope Global -Force Remove-Variable -Name defaultStartOfLogsExtractPeriod -Scope Global -Force Remove-Variable -Name delimeter -Scope Global -Force Remove-Variable -Name exceptionColour -Scope Global -Force Remove-Variable -Name extractColour -Scope Global -Force Remove-Variable -Name folderColour -Scope Global -Force Remove-Variable -Name folderIdArray -Scope Global -Force Remove-Variable -Name folderNameArray -Scope Global -Force Remove-Variable -Name folderRobotsIdArray -Scope Global -Force Remove-Variable -Name folderRobotsNameArray -Scope Global -Force Remove-Variable -Name GETheaders -Scope Global -Force Remove-Variable -Name goodColour -Scope Global -Force Remove-Variable -Name infoColour -Scope Global -Force Remove-Variable -Name jobEndDateArray -Scope Global -Force Remove-Variable -Name jobStartDateArray -Scope Global -Force Remove-Variable -Name machineColour -Scope Global -Force Remove-Variable -Name month -Scope Global -Force Remove-Variable -Name orchestratorURL -Scope Global -Force Remove-Variable -Name password -Scope Global -Force Remove-Variable -Name POSTbody -Scope Global -Force Remove-Variable -Name POSTheaders -Scope Global -Force Remove-Variable -Name POSTresponse -Scope Global -Force Remove-Variable -Name queueColour -Scope Global -Force Remove-Variable -Name QueuesColour -Scope Global -Force Remove-Variable -Name robotColour -Scope Global -Force Remove-Variable -Name robotIdtoNameArray -Scope Global -Force Remove-Variable -Name robotIdtoNameExtractArray -Scope Global -Force Remove-Variable -Name scriptPath -Scope Global -Force Remove-Variable -Name Seperator -Scope Global -Force Remove-Variable -Name tenancyName -Scope Global -Force Remove-Variable -Name triggerColour -Scope Global -Force Remove-Variable -Name username -Scope Global -Force Remove-Variable -Name windowsAuth -Scope Global -Force Remove-Variable -Name year -Scope Global -Force Remove-Variable -Name YellowColor -Scope Global -Force } ################################################################################ # Run script ################################################################################ #------------------------------------------------------------------------------- # Clear screen and see whats set up for env #------------------------------------------------------------------------------- cls #------------------------------------------------------------------------------- # Show available colour combinations #------------------------------------------------------------------------------- # x-Show-Colors # x-Show-Colors-On-Colors #------------------------------------------------------------------------------- # Show environment #------------------------------------------------------------------------------- # x-write-log "Environment Details..." -color $infoColour # Get-ChildItem Env:* | Select-Object -Property Name,Value | Sort-Object Name | Out-String #------------------------------------------------------------------------------- # Main Body #------------------------------------------------------------------------------- a-start b-main z-exit #------------------------------------------------------------------------------- # What variables need to be removed #------------------------------------------------------------------------------- # Get-Variable -Scope 0 #------------------------------------------------------------------------------- # ...and exit stage left #------------------------------------------------------------------------------- Remove-Variable -Name logFilename -Scope Global -Force exit $global:exitCode ################################################################################ # Exit Program ################################################################################