Skip to content

Instantly share code, notes, and snippets.

@grenzi
Created August 26, 2024 18:13
Show Gist options
  • Save grenzi/166b81aaf72740eb4c267173465cfb02 to your computer and use it in GitHub Desktop.
Save grenzi/166b81aaf72740eb4c267173465cfb02 to your computer and use it in GitHub Desktop.
See if power bi on-prem data gateways are happily running / available, using a service principal account
Import-Module MicrosoftPowerBIMgmt
$clientId="REDACTED"
$tenantId="REDACTED"
$clientSecret="REDACTED"
$securePassword = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $clientId, $securePassword
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId $tenantId
$gwlist = Invoke-PowerBIRestMethod -Url gateways -Method Get | ConvertFrom-Json
foreach ($gateway in $gwlist) {
$gwid = $gateway.value.Id
$gw = Invoke-PowerBIRestMethod -Url "gateways/{$gwid}" -Method Get | ConvertFrom-Json
if (-not "Live" -eq $gw.gatewayStatus){
#your code here for when the gateway is not showing all ok
write-host "panic oh noes"
}
}
Disconnect-PowerBIServiceAccount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment