Module Name | Module Guid | Version |
---|---|---|
PowerBIPS |
163a1640-a4f2-4b1f-a3af-2796ad56200b |
2.0.1.3 |
A PowerShell module that wrap's the Power BI REST API
More samples of usage here:
- https://ruiromanoblog.wordpress.com/2015/03/03/create-a-real-time-it-dashboard-with-powerbips/
- https://github.com/DevScope/powerbi-powershell-modules/blob/master/Modules/PowerBIPS/Samples
https://www.powershellgallery.com/packages/PowerBIPS
Install-Module -Name PowerBIPS
# Or without admin priviledge:
Install-Module -Name PowerBIPS -Scope CurrentUser
Get-Process | Out-PowerBI -verbose
Set-PBIWorkspace -id "GUID"
Get-PBIReport | Export-PBIReport -destinationFolder ".\Output"
Get-PBIReport -groupId "WorkspaceId" | Set-PBIReportsDataset -targetDatasetId "DataSetId"
$tenantId = "MyTenant.onmicrosoft.com"
$clientId = "App Id"
$clientSecret = "App Secret"
$authToken = Get-PBIAuthToken -clientId $clientId -clientSecret $clientSecret -tenantId $tenantId
$reports = Get-PBIReport -authToken $authToken -groupId "Workspace Id" -Verbose
$reports
# Get the authentication token using ADAL library (OAuth)
$authToken = Get-PBIAuthToken -Verbose
$workspaceId = "GUID"
$datasetName = "Computer Monitoring"
$reset = $false
$computers = @($env:COMPUTERNAME)
# Change to the destination workspace
Set-PBIWorkspace -id $workspaceId
# Test the existence of the dataset and if exists retrieve the metadata
$dataSetSchema = Get-PBIDataSet -authToken $authToken -name $datasetName -Verbose
if (-not $dataSetSchema)
{
# If cannot find the DataSet create a new one with this schema
$dataSetSchema = @{name = $datasetName
; tables = @(
@{name = "Counters"
; columns = @(
@{ name = "ComputerName"; dataType = "String"; isHidden = "true" }
, @{ name = "TimeStamp"; dataType = "DateTime" }
, @{ name = "CounterSet"; dataType = "String" }
, @{ name = "CounterName"; dataType = "String" }
, @{ name = "CounterValue"; dataType = "Double" }
)
}
,
@{name = "Computers"
; columns = @(
@{ name = "ComputerName"; dataType = "String" }
, @{ name = "Domain"; dataType = "string" }
, @{ name = "Manufacturer"; dataType = "string" }
)
;measures = @(
@{name="Average CPU"; expression="CALCULATE(AVERAGE('Counters'[CounterValue]) / 100, FILTER('Counters', 'Counters'[CounterSet] = ""Processor(_Total)"" && 'Counters'[CounterName] = ""% Processor Time""))"; formatString="0.00%"}
)
}
)
; relationships = @(
@{
name = [guid]::NewGuid().ToString()
; fromTable = "Computers"
; fromColumn = "ComputerName"
; toTable = "Counters"
; toColumn = "ComputerName"
; crossFilteringBehavior = "oneDirection"
})
}
$dataSetSchema = New-PBIDataSet -authToken $authToken -dataSet $dataSetSchema -Verbose
}
else
{
# If a dataset exists, delete all its data
if ($reset)
{
Clear-PBITableRows -authToken $authToken -dataSetId $dataSetSchema.Id -tableName "Counters" -Verbose
Clear-PBITableRows -authToken $authToken -dataSetId $dataSetSchema.Id -tableName "Computers" -Verbose
}
}
# Get Computer Info
$computers |% {
$computerInfo = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $_
@{
ComputerName = $_
; Domain = $computerInfo.Domain
; Manufacturer = $computerInfo.Manufacturer
} | Add-PBITableRows -authToken $authToken -dataSetId $dataSetSchema.Id -tableName "Computers" -batchSize 100 -Verbose
}
# Collect data from continuosly in intervals of 5 seconds
$counters = Get-Counter -ComputerName $computers -ListSet @("processor", "memory", "physicaldisk")
$counters | Get-Counter -Continuous -SampleInterval 5 |%{
# Parse the Counters into the schema of the PowerBI dataset
$pbiData = $_.CounterSamples | Select @{Name = "ComputerName"; Expression = {$_.Path.Split('\')[2]}} `
, @{Name="TimeStamp"; Expression = {$_.TimeStamp.ToString("yyyy-MM-dd HH:mm:ss")}} `
, @{Name="CounterSet"; Expression = {$_.Path.Split('\')[3]}} `
, @{Name="CounterName"; Expression = {$_.Path.Split('\')[4]}} `
, @{Name="CounterValue"; Expression = {$_.CookedValue}}
$pbiData | Add-PBITableRows -authToken $authToken -dataSetId $dataSetSchema.Id -tableName "Counters" -batchSize 100 -Verbose
Write-Output "Sleeping..."
}