Service Principal Not able to use Get-PowerBIWorkspace -All
Take with a grain of salt because I am outside of my comfort zone with coding but here's some powershell code that does work for me. The important parts at least. Maybe it will give you an idea.
#Import
Import-Module MicrosoftPowerBIMgmt
Import-Module MicrosoftPowerBIMgmt.Profile
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ### bypass tls protocal restrictions
#The Azure app was created on my login/account. If we go live with this need to replace with service account, might have to create a new app or figure out a different way.
$password = 'YourPassword' | ConvertTo-SecureString -asPlainText -Force
$username = 'YourUserNameEmail'
$credential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username, $password
Connect-PowerBIServiceAccount -Credential $credential
#directory to csv export
$ActivityLogsPathWorkSpaces = "\\blah\blah\Workspaces.csv"
$ActivityLogsPathReports = "\\blah\blah\Reports.csv"
#Export to csv file
$workspaceReports = @()
# Get the data
$workspaces = Get-PowerBIWorkspace -All
# Get the report and dataset data for each workspace
foreach ($workspace in $workspaces) {
$reports = Get-PowerBIReport -WorkspaceId $workspace.Id
$datasets = Get-PowerBIDataset -WorkspaceId $workspace.Id
$reports | Add-Member -NotePropertyName WorkspaceId -NotePropertyValue $workspace.Id
$workspaceReports += $reports
}
# Output the results for each type to CSV files
$workspaces | Export-CSV -Force -Path $ActivityLogsPathWorkSpaces
Disconnect-PowerBIServiceAccount
I can't remember if there was an Azure app or something like that for authentication. I made a note to myself at the time so appears so.