# Create HttpClient$client=[System.Net.Http.HttpClient]::new()# Set the API request URL$url="https://graph.microsoft.com/v1.0/devices"# Send the request and get the response as a stream$response=$client.GetStreamAsync($url).Result# Process the stream in chunks (for example, you can parse the JSON incrementally here)$jsonReader=New-ObjectSystem.IO.StreamReader($response)while(($line=$jsonReader.ReadLine())-ne$null){# Process each line or chunk of data hereWrite-Host$line}
# Define the function that handles data fetching and processingfunctionGet-DeviceData{$url="https://graph.microsoft.com/v1.0/devices"$client=[System.Net.Http.HttpClient]::new()$response=$client.GetStreamAsync($url).Result$jsonReader=New-ObjectSystem.IO.StreamReader($response)while(($line=$jsonReader.ReadLine())-ne$null){# Process each line and update your GUI hereWrite-Host$line}}# Start the job asynchronously$job=Start-Job-ScriptBlock{Get-DeviceData}# Wait for the job to finish (optional)$job|Wait-Job$job|Receive-Job
# Define the function to handle the async requestfunctionGet-DeviceDataAsync{$url="https://graph.microsoft.com/v1.0/devices"$client=[System.Net.Http.HttpClient]::new()# Perform async operationreturn$client.GetStreamAsync($url)}# Use Start-Job to run the function asynchronously$job=Start-Job-ScriptBlock{$task=Get-DeviceDataAsync$task.Result# Waits for the task to complete and gets the result}# You can continue to do other things in the UI while the job runsWrite-Host"Async task running in the background..."# Optionally wait for the job to finish and get the result$job|Wait-Job$job|Receive-Job
Warning
LINK
You are about to visit a link which has been flagged with the above content warnings. Do you wish to continue?