I was working to generate DLP logs with the help of the script present here
body = @{grant_type="client_credentials";resource=$APIResource;client_id=$AppClientID;client_secret=$ClientSecretValue}
Write-Host -ForegroundColor Blue -BackgroundColor white "Obtaining authentication token..." -NoNewline
try{
$oauth = Invoke-RestMethod -Method Post -Uri "$loginURL/$tenantdomain/oauth2/token?api-version=1.0" -Body $body -ErrorAction Stop
$OfficeToken = @{'Authorization'="$($oauth.token_type) $($oauth.access_token)"}
Write-Host -ForegroundColor Green "Authentication token obtained"
} catch {
write-host -ForegroundColor Red "FAILED"
write-host -ForegroundColor Red "Invoke-RestMethod failed."
Write-host -ForegroundColor Red $error[0]
exit
}
This part of the code helps to generate the access token.
The script seems to work fine, until about 700mb of data is exported. For me, it takes around 3-4 hours to run and get this 700mb worth of data. Now, the issue is, I believe that the only reason this is happening is because the Access token is defaulting. And since I am new to PowerShell, I haven't been able to write the part of the code that could help me generate a new token every 3-4 hours. Any documentation that might help me would be of great help since I have not been able to find anything of substance on the internet regarding my request. If it's not about the access token, what else could it be about? Please help! thanks in advance!
$StopWatch = [System.Diagnostics.Stopwatch]::StartNew() if($StopWatch.Elapsed.TotalSeconds -ge 3599){$OfficeToken = Get-Token; $StopWatch.Restart()}
I tried using this particular piece of code to generate it every hour, but that doesn't seem to help us either.I was expecting it to work flawlessly after this, but alas, that isn't the case.
The Script in question does not produce information for large sources of data, as confirmed from the author of the script.. I ran the script for other days and it worked fine.