Add-Type -AssemblyName PresentationFramework $global:fqdn = "" $global:token = '' $global:response = " " $timestamp = Get-Date -Format o | ForEach-Object { $_ -replace ":", "." } $report="./AccountsInUse-GA.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-LeAccountGroups { Param ( [string]$orderBy = "Name", [string]$Direction = "Asc", [string]$Count = "10000", [string]$Include = "members" ) # 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 = @{ orderBy = $orderBy direction = $Direction count = $Count include = $Include } $Parameters = @{ Uri = 'https://' + $global:fqdn + '/publicApi/v7-preview/account-groups' Headers = $Header Method = 'GET' body = $Body ContentType = 'application/json' } $Response = Invoke-RestMethod @Parameters $Response.items } #Write header to CSV file "TimeStamp," | Out-File $report -Force -NoNewLine $acctgps = Get-LeAccountGroups ForEach ($acctgrp in $acctgps){ $acctgrp.name | Out-File $report -Append -NoNewLine "," | Out-File $report -Append -NoNewLine } "" | Out-File $report -Append While ($true) { Get-Date -format "ddMMMyyyy HH:mm:ss"| Out-File $report -Append -NoNewLine ForEach ($acctgrp in $acctgps) { $acctmem = $acctgrp.members $acctmemIU = $acctgrp.members | Where-Object inUse -EQ True "," + $acctmemIU.Count + " / " + $acctmem.count | Out-File $report -Append -NoNewLine } "" | Out-File $report -Append Start-Sleep -Seconds 300 }