Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Report on Attribute Value History from FIM/MIM MV
# Install-Module PowerBIPS -RequiredVersion 1.2.0.9 -Force
Import-Module PowerBIPS -RequiredVersion 1.2.0.9
Import-Module LithnetMiisAutomation
$credentials = Get-Credential
# PowerBI App
$clientID = "4036df76-4de6-43cb-afe6-1234567890"
$authtoken = Get-PBIAuthToken -ClientId $clientID -Credential $credentials
# WaterMark End Date File
$WaterMarkFilePath = "C:\Reports\Enddate\EDateWMark.txt"
if(!(Test-Path $WaterMarkFilePath))
{
# No previous seed, create new file
$WaterMarkFile = New-Item -Path $WaterMarkFilePath -ItemType File
$WaterMarkFile = Get-Item -Path $WaterMarkFilePath
$seedDate = get-Date
# make first seed 1 yr ago
$seedDate = $seedDate.AddDays(-365)
$seedDate | Out-File $WaterMarkFile
[dateTime]$PreviousEndDateWatermark = $seedDate
}
else
{
# Get previous watermark
$WaterMarkFile = Get-Item -Path $WaterMarkFilePath
$Watermark = Get-Content $WaterMarkFile
foreach ($line in $Watermark){
if ($line){[dateTime]$PreviousEndDateWatermark = $line}
}
}
# MV Users
$MVResults_raw = Get-MVObject -ObjectType person
# With an EndDate Newer that WaterMark
$MVResults = $MVResults_raw | Where-Object {($_.Attributes.employeeEndDate.Values.LineageTime -gt $PreviousEndDateWatermark)}
$MVResults.Count
# Report Execution Date for PBI Report
$strDate = get-date
$MAName = "SSF MA"
$EmpPBILoad = @()
foreach ($EmpEndDateUser in $MVResults){
$SSFCS = $EmpEndDateUser.CSMVLinks | Where-Object {($_.ManagementAgentName -eq $MAName)}
if ($SSFCS) {
$csObj = Get-CSObject -DN $SSFCS.ConnectorSpaceDN -MA $MAName
$mvObj = Get-MVObject -ID $csObj.MvGuid.Guid
if ($mvObj.Attributes.employeeEndDate.Values.LineageTime){$EmpEndDateReceived = $mvObj.Attributes.employeeEndDate.Values.LineageTime}
# Set EndDateWatermark
if ($EmpEndDateReceived.Date){
# $EmpEndDateReceived
if ($EmpEndDateReceived -gt $PreviousEndDateWatermark){
# User has an EndDate Received from SSF newer that what we have previously seen
$blnNewEndDateDate = $true
# $blnNewEndDateDate
# Set new watermark if newer
if ($NewEndDateWatermark){
if ($EmpEndDateReceived -gt $NewEndDateWatermark){
$NewEndDateWatermark = $EmpEndDateReceived
write-host "New EndDateWatermark $($NewEndDateWatermark)"
}
} else {
[datetime]$NewEndDateWatermark = $EmpEndDateReceived
write-host "New EndDateWatermark $($NewEndDateWatermark)"
}
# Build PS Object for injection to PBI
if ($mvObj.Attributes.employeeActive.Values.valueString){$EmpActive = $mvObj.Attributes.employeeActive.Values.valueString ; $EmpActive}
if ($mvObj.Attributes.employeeEndDate.Values.valueString){$EmpEndDate = $mvObj.Attributes.employeeEndDate.Values.valueString; $EmpEndDate }
if ($mvObj.Attributes.displayName.Values.valueString){$EmpDisplayname = $mvObj.Attributes.displayName.Values.valueString; $EmpDisplayname}
if ($mvObj.Attributes.accountName.Values.valueString){$EmpAccountName = $mvObj.Attributes.accountName.Values.valueString; $EmpAccountName}
} else {
$blnNewEndDateDate = $false
# $blnNewEndDateDate
}
}
if ($blnNewEndDateDate) {
# New EndDate info we need to send to PowerBI
$Emp = New-Object PSObject -prop @{
Date = $strDate
AccountName = $EmpAccountName
DisplayName = $EmpDisplayname
Active = $EmpActive
EndDate = $EmpEndDate
EndDateReceived = $EmpEndDateReceived
}
$EmpPBILoad += $Emp
}
}
}
if($EmpPBILoad.Count -gt 0){
# Output new Watermark
$NewEndDateWatermark | Out-File $WaterMarkFile
# Write Out the User data to PowerBI
$DataSet = Get-PBIDataSet -authToken $authToken -Name "EmployeeEndDateReport"
$EmpPBILoad | Out-PowerBI -AuthToken $authToken -dataSetName $DataSet.name -tableName "Employee" -verbose
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.