Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Populate PowerBI with xMatters Users
# 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
$OrgMVResults_raw = Get-MVObject -ObjectType person
$OrgMVResults = $OrgMVResults_raw | Where-Object {($_.Attributes.employeeActive.Values.ValueBoolean -eq $True)}
$OrgMVResults.Count
$xMattersCS = $null
$xMattersMA = "xMatters"
$xMattersPBIUsers = @()
foreach ($OrgUser in $OrgMVResults){
$xMattersCS = $OrgUser.CSMVLinks | Where-Object {($_.ManagementAgentName -eq $xMattersMA)}
if ($xMattersCS){
# Build PS Object for injection to PBI
if ($OrgUser.Attributes.accountName.Values.valueString){$EmpAccount = $OrgUser.Attributes.accountName.Values.valueString}else{$EmpAccount = $null}
if ($OrgUser.Attributes.employeeActive.Values.valueBoolean){[boolean]$EmpActive = $OrgUser.Attributes.employeeActive.Values.valueBoolean}else{[boolean]$EmpActive = $false}
if ($OrgUser.Attributes.city.Values.valueString){$EmpCity = $OrgUser.Attributes.city.Values.valueString}else{$EmpCity = $null}
if ($OrgUser.Attributes.displayName.Values.valueString){$EmpDisplay = $OrgUser.Attributes.displayName.Values.valueString}else{$EmpDisplay = $null}
if ($OrgUser.Attributes.company.Values.valueString){$EmpCompany = $OrgUser.Attributes.company.Values.valueString}else{$EmpCompany = $null}
if ($OrgUser.Attributes.department.Values.valueString){$EmpDept = $OrgUser.Attributes.department.Values.valueString}else{$EmpDept = $null}
if ($OrgUser.Attributes.division.Values.valueString){$EmpDiv = $OrgUser.Attributes.division.Values.valueString}else{$EmpDiv = $null}
if ($OrgUser.Attributes.employeeType.Values.valueString){$EmpType = $OrgUser.Attributes.employeeType.Values.valueString}else{$EmpType = $null}
if ($OrgUser.Attributes.officeLocation.Values.valueString){$EmpOffice = $OrgUser.Attributes.officeLocation.Values.valueString}else{$EmpOffice = $null}
if ($OrgUser.Attributes.postalCode.Values.valueString){$EmpPCode = $OrgUser.Attributes.postalCode.Values.valueString}else{$EmpPCode = $null}
if ($OrgUser.Attributes.st.Values.valueString){$EmpState = $OrgUser.Attributes.st.Values.valueString}else{$EmpState = $null}
if ($OrgUser.Attributes.street.Values.valueString){$EmpStreet = $OrgUser.Attributes.street.Values.valueString}else{$EmpStreet = $null}
if ($OrgUser.Attributes.timezone.Values.valueString){$EmpTZ = $OrgUser.Attributes.timezone.Values.valueString}else{$EmpTZ = $null}
if ($OrgUser.Attributes.title.Values.valueString){$EmpTitle = $OrgUser.Attributes.title.Values.valueString}else{$EmpTitle = $null}
#Manager
foreach ($ref in $orgUser.DNAttributes){
if ($ref.Name -eq 'manager'){
$MgrDN = [array]$ref.Values.Item(0).DN
$Manager = $MgrDN | Get-MVObject
if ($Manager){
$EmpMgrAccountName = $Manager.Attributes.accountName.Values.value
$EmpMgrDisplayName = $Manager.Attributes.displayName.Values.value
}else {
$EmpMgrAccountName = $null
$EmpMgrDisplayName = $null
}
}
}
$EmpRecord = New-Object PSObject -prop @{
accountName = $EmpAccount
displayName = $EmpDisplay
city = $EmpCity
company = $EmpCompany
department = $EmpDept
division = $EmpDiv
employeeType = $EmpType
employeeActive = $EmpActive
managerID = $EmpMgrAccountName
managerName = $EmpMgrDisplayName
officeLocation = $EmpOffice
postalCode = $EmpPCode
state = $EmpState
street = $EmpStreet
timezone = $EmpTZ
title = $EmpTitle
}
$xMattersPBIUsers += $EmpRecord
}
}
$xMattersPBIUsers.Count
if($xMattersPBIUsers.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 xMattersUsers -Verbose
$xMattersPBIUsers | Out-PowerBI -AuthToken $authToken -dataSetName $DataSet.name -tableName xMattersUsers -verbose
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment