Created
March 23, 2021 23:03
-
-
Save matt40k/7ccb179255b8b15643a9efd5eff63395 to your computer and use it in GitHub Desktop.
Simple PowerShell script to use the Google Search API to search for public Power BI reports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$apikey = "" | |
$baseUri = "https://www.googleapis.com/customsearch/v1" | |
$cx = "" | |
$query = "site:https://app.powerbi.com" | |
function GetSearchResults([string]$start) | |
{ | |
$uri = "$($baseUri)?key=$($apikey)&cx=$($cx)&q=$($query)&start=$($start)" | |
$c = Invoke-WebRequest -Uri $uri -UseBasicParsing -Method Get | |
$results = $c.Content | ConvertFrom-Json | |
foreach ($result in $results.items) | |
{ | |
$reportUri = $($result.link) | |
if ($reportUri.StartsWith("https://app.powerbi.com/view")) | |
{ | |
Add-Content -Value $reportUri -Path "urls.csv" | |
} | |
} | |
return $results.queries.nextPage.startIndex | |
} | |
[int]$counter = 0 | |
while ($counter -le 1000) | |
{ | |
$counter = GetSearchResults($counter) | |
Start-Sleep -Seconds 4 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment