Add-Type -AssemblyName PresentationFramework $global:fqdn = "" $global:token = '' $global:response = " " $export="./Data/LauncherSessions.csv" $code = @" public class SSLHandler {public static System.Net.Security.RemoteCertificateValidationCallback GetSSLHandler() {return new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });} } "@ Add-Type -TypeDefinition $code $new = [Environment]::NewLine function Get-Launchers { Param ( [string]$orderBy = "name", [string]$testType = "continuousTest", [string]$Direction = "Asc", [string]$Count = "10000" ) # this is only required for older version of PowerShell/.NET [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls11 # WARNING: ignoring SSL/TLS certificate errors is a security risk [System.Net.ServicePointManager]::ServerCertificateValidationCallback = [SSLHandler]::GetSSLHandler() $Header = @{ "Accept" = "application/json" "Authorization" = "Bearer $global:token" } $Body = @{ testType = $testType orderBy = $orderBy direction = $direction count = $Count } $Parameters = @{ Uri = 'https://' + $global:fqdn + '/publicApi/v6-preview/launchers' Headers = $Header Method = 'GET' body = $Body ContentType = 'application/json' } $Response = Invoke-RestMethod @Parameters $Response.items } $launchers = Get-Launchers "TimeStamp" | Out-File $export -Force -NoNewLine ForEach ($launcher in $launchers) { # Header $launcher.machinename + "," | Out-File $export -Append -NoNewLine } "" | Out-File $export -Append While ($true) { Get-Date -format "ddMMMyyyy HH:mm:ss"| Out-File $export -Append -NoNewLine "," | Out-File $export -Append -NoNewLine $launchers = Get-Launchers ForEach ($launcher in $launchers) { $launcher.sessions.ToString() + "," | Out-File $export -Append -NoNewLine } "" | Out-File $export -Append Start-Sleep -Seconds 300 }