Introduction

Datamining Reports (DMR) provide a quick and easy way to produce a bespoke report which can list a set of users, applications or devices (or a combination of all three) based on a certain set of criteria.


Blueprints are a powerful way to group users, applications or devices to use as a pivot point for reports, or group for automation tasks.


Wouldn't it be useful to combine these two? So create a DMR with custom criteria, then use the DMR output (a custom set of users/apps/devices) to populate a Blueprint and drive automation. 


Use Case

  • Use the Windows 11 Readiness DMR to just show the Windows 11 compatible devices, then add these devices into a Blueprint (using this script)
  • Use automation to email the primary users of these devices with a survey to ask if they'd be willing to be part of a Windows 11 pilot
  • Where the users agrees, add them to the Deployment Unit for the Windows 11 pilot


The script is module agnostic so will run on any module DMR report (you just need to give it the report Id’s) and it will work out the rest. Any items that fall outside of the DMR reporting will also be removed automatically.


Setup

  • Click Devices -> All Devices
  • Click the Datamining Report dropdown -> Win 11 Compatibility Report
  • Click Column Layout, Filter, Sort
  • In the Win 11 Compatible row, add a Filter Expression: = 'Compatible'

  • Click Apply Changes, only the compatible devices will be displayed
  • Click Menu -> Save -> Type a name for the report such as Win 11 Compat Devices
  • Make a note of the Id of this folder as shown in the report header (17 in this case)

  • Click Administration -> Devices -> PowerShell Scripts
  • Expand the Devices, Custom Script node
  • Click here to create a new script
  • Click the edit button (scroll icon)
  • Copy/paste the script below in
  • Click OK
  • Use the column picker button to add the following columns: Args 1, Grant Access 1
  • In Args 1 enter the ID of the dataming report
  • In Grant Access 1 add Project Admin

  • Click Save Changes

Test the Script

  • Click the play button for the script (scroll to the right)
  • Click Administration -> Blueprints
  • Expand DMR Blueprints -> Devices -> Win 11 Compat Devices
  • Click Show Counts
  • The number of devices will be shown


Restarting the ManagementStudio client will reload the Blueprint filter in the Devices module so that the Win 11 compatible devices can be listed.

  • Click Devices -> All Devices -> Blueprints -> DMR Reports -> Devices -> Win11 Compat Devices



Script

#ScriptArgs1 is the DMR Report Ids in a comma delimited format
# Debug line: $ScriptArgs.ScriptArg1 ="14,10, 13"

$ReportIds = $ScriptArgs.ScriptArg1
$ReportIds = $ReportIds.split(",").Trim()

$BPRoot = "DMR Blueprints"

foreach($ReportId in $ReportIds) {   
    $schema = Get-MSDataminingReportSchema -ReportId $ReportId
    $moduleId = $schema.TopTier.ModuleId

    Switch ($moduleId) {
        1 {$module = "Applications"; $key = "Applications_AppId"}
        2 {$module = "UserMigrations"; $key = "UserMigrations_MigrationId"}
        3 {$module = "Devices"; $key = "Devices_DeviceId"}
        4 {$module ="Mailboxes"; $key = "Mailboxes_MailId" }
        5 {$module = "BespokeModule"; $key = "BespokeModule_BespokeId"}
        6 {$module = "DeploymentUnits"; $key = "DeploumentUnits_DeployUnitId"}
    }

    $InScope = Get-MSDataminingReportById -ReportId $ReportId -HeaderFormat PrefixedName 
    if($InScope.data.rows.count -eq 0) {continue}
    $InScopeIds = $Inscope.data.Rows.$key

    $BlueprintName = "{0}\{1}\{2}" -f $BProot, $module, $inscope.Status.ReportName
    Add-MSModuleItemsToBlueprint -Module $module -BlueprintPath $BlueprintName -Ids $InScopeIds -CreateIfNotFound | Out-Null

    $Blueprint = Get-MSConfigBlueprint -BlueprintIdOrPath $BlueprintName
    $BlueprintItems = Get-MSDataminingReport -BlueprintIds $Blueprint.BlueprintId -Module $module -Fields @('Id') -HeaderFormat DisplayName
    $BlueprintItemIds = $BlueprintItems.Data.Rows."Id"

    $RemoveIds = @()
    $BlueprintItemIds | ForEach-Object {
        if ($InscopeIds -notcontains $_) {
            #Write-Host "`$InscopeId does not contain the ItemId [$_]"
            $RemoveIds += $_
        }
    }

    if($RemoveIds) {Remove-MSModuleItemsFromBlueprint -Module $module -Ids $RemoveIds -BlueprintId $Blueprint.BlueprintId | Out-Null}

}