Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Last active November 29, 2017 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenjrobinson/a62d55403b48d07349962092333e0d37 to your computer and use it in GitHub Desktop.
Save darrenjrobinson/a62d55403b48d07349962092333e0d37 to your computer and use it in GitHub Desktop.
Populate PowerBI with xMatters Sites from MIM
# Install-Module PowerBIPS -RequiredVersion 1.2.0.9 -Force
Import-Module PowerBIPS -RequiredVersion 1.2.0.9
Import-Module LithnetMiisAutomation
$clientID = "4036df76-4de6-43cb-afe6-1234567890"
$authtoken = Get-PBIAuthToken -ClientId $clientID
# MV Users
$SitesMVResults = Get-MVObject -ObjectType site
$SitesMVResults.Count
$SitesPBIDataLoad = @()
foreach ($Site in $SitesMVResults){
# Build PS Object for injection to PBI
if ($Site.Attributes.displayName.Values.valueString){$siteName = $Site.Attributes.displayName.Values.valueString}else{$siteName = $null}
if ($Site.Attributes.longitude.Values.valueString){$siteLong = $Site.Attributes.longitude.Values.valueString}else{$siteLong = $null}
if ($Site.Attributes.latitude.Values.valueString){$siteLat = $Site.Attributes.latitude.Values.valueString}else{$siteLat = $null}
# change format of Latitude (prob only work for southern hemisphere)
if($siteLat){
if($siteLat[0] -eq ("-")){
$NewsiteLat = $siteLat.Replace("-","") + " S"
$NewsiteLat
}
}
# change format of Longitude (prob only work for southern hemisphere)
if($siteLong){
$NewsiteLong = $siteLong + " E"
$NewsiteLong
}
$SiteRecord = New-Object PSObject -prop @{
displayName = $siteName
longitude = $NewsiteLong
latitude = $NewsiteLat
geo = $NewsiteLat + ", " + $NewsiteLong
}
$SitesPBIDataLoad += $SiteRecord
}
$SitesPBIDataLoad.Count
if($SitesPBIDataLoad.Count -gt 0){
# Write Out the User data to PowerBI
$DataSet = Get-PBIDataSet -authToken $authToken -Name "xMatters"
# Clear Table
Clear-PBITableRows -authToken $authtoken -dataSetId $DataSet.id -tableName xMattersSites -Verbose
$SitesPBIDataLoad | Out-PowerBI -AuthToken $authToken -dataSetName $DataSet.name -tableName xMattersSites -verbose
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment