Development snapshot 2026-10-25 (4.0.0-beta1 + fixes)

This commit is contained in:
Mikael Karlsson
2026-10-25 20:04:55 +11:00
parent 7869619510
commit 325e3a6b12
88 changed files with 21308 additions and 1081 deletions
@@ -26,6 +26,26 @@ function Get-SettingsCatalogPolicyBuffer {
return $script:_curSettingsCatologPolicy
}
# The @odata.type of a setting instance, inferred from the value it carries
# when the payload has none (a GET made with odata.metadata=none, and the
# exports hydrated that way).
function Get-SettingInstanceODataType {
param($SettingInstance)
$type = [string]$SettingInstance.'@odata.type'
if ($type) { return $type }
foreach ($pair in @(
@('groupSettingCollectionValue', '#microsoft.graph.deviceManagementConfigurationGroupSettingCollectionInstance'),
@('groupSettingValue', '#microsoft.graph.deviceManagementConfigurationGroupSettingInstance'),
@('choiceSettingCollectionValue', '#microsoft.graph.deviceManagementConfigurationChoiceSettingCollectionInstance'),
@('choiceSettingValue', '#microsoft.graph.deviceManagementConfigurationChoiceSettingInstance'),
@('simpleSettingCollectionValue', '#microsoft.graph.deviceManagementConfigurationSimpleSettingCollectionInstance'),
@('simpleSettingValue', '#microsoft.graph.deviceManagementConfigurationSimpleSettingInstance'))) {
if ($SettingInstance.PSObject.Properties[$pair[0]] -and $null -ne $SettingInstance.($pair[0])) { return $pair[1] }
}
return ''
}
function Add-SettingsSetting {
param(
$SettingInstance,
@@ -37,6 +57,7 @@ function Add-SettingsSetting {
if (-not $SettingInstance) { return }
$ctx = Get-CurrentDocumentationContext
$instanceType = Get-SettingInstanceODataType $SettingInstance
$defaultValue = $null
$tableValue = $null
@@ -97,8 +118,12 @@ function Add-SettingsSetting {
$settingDescription = $settingsDef.description.Trim([Environment]::NewLine).Trim("`n")
}
# The id comes from the schema when it resolved, else from the instance: a
# row without a schema still needs its identity (EntityKey, fallback names).
$settingId = if ($settingsDef) { $settingsDef.Id } else { $SettingInstance.settingDefinitionId }
$settingInfo = [PSCustomObject]@{
SettingId = $settingsDef.Id
SettingId = $settingId
SettingKey = ''
SettingName = $settingsDef.Name
Name = $settingName
@@ -116,7 +141,7 @@ function Add-SettingsSetting {
Level = $ItemLevel
Parent = $null
Show = $show
Type = $SettingInstance.'@odata.type'
Type = $instanceType
PropertyIndex = 0
RowIndex = 0
ChildSettings = @()
@@ -126,7 +151,7 @@ function Add-SettingsSetting {
$script:_curSettingsCatologPolicy += $settingInfo
}
switch ($SettingInstance.'@odata.type') {
switch ($instanceType) {
'#microsoft.graph.deviceManagementConfigurationChoiceSettingInstance' {
# Single dropdown
@@ -183,8 +208,12 @@ function Add-SettingsSetting {
# Catalog uses $settingsDef.childIds. Old code at L1347-1354.
$childIds = if ($ctx.CurrentObject.templateReference.templateId -and $SettingsDefs) {
$SettingsDefs.id
} else {
} elseif ($settingsDef.childIds) {
$settingsDef.childIds
} else {
# No schema for this group (offline, or an id the generic
# endpoint does not serve): walk the children the item has.
@($groupSettingCollection.children | ForEach-Object { $_.settingDefinitionId })
}
foreach ($childId in $childIds) {
$childSetting = $groupSettingCollection.children | Where-Object settingDefinitionId -EQ $childId | Select-Object -First 1
@@ -242,7 +271,7 @@ function Add-SettingsSetting {
}
default {
Write-Log "Unhandled settings catalog instance type: $($SettingInstance.'@odata.type')" 2
Write-Log "Unhandled settings catalog instance type: $instanceType" 2
return
}
}
@@ -274,15 +303,13 @@ function Add-SettingsSetting {
#
# Rows are returned rather than pushed onto the context, so the caller decides
# whether they belong in the main settings table or in a table of their own.
function Get-SettingsCatalogDocumentationRows
# Bind the context to the session-wide schema caches and make sure the
# configuration categories are loaded. Shared by Get-SettingsCatalogDocumentationRows
# and the handlers that walk a single settings instance themselves (reusable
# settings), which need the same category resolution.
function Initialize-SettingsCatalogSchemaCache
{
param(
$Settings,
[DocumentationContext]$Context
)
$cfgSettings = @($Settings)
if ($cfgSettings.Count -eq 0) { return @() }
param([DocumentationContext]$Context)
# Generic schema caches (session-persistent, shared by reference so later
# writes by the walker warm the cache automatically). Definitions are generic
@@ -306,6 +333,19 @@ function Get-SettingsCatalogDocumentationRows
Write-LogError 'Failed to fetch configuration categories' $_.Exception
}
}
}
function Get-SettingsCatalogDocumentationRows
{
param(
$Settings,
[DocumentationContext]$Context
)
$cfgSettings = @($Settings)
if ($cfgSettings.Count -eq 0) { return @() }
Initialize-SettingsCatalogSchemaCache $Context
# Seed the definition cache from inline settingDefinitions on each setting
foreach ($cfgSetting in $cfgSettings) {
@@ -491,6 +491,126 @@ function Add-DocumentationDefenderFirewallSettings {
}
}
function Get-DocumentationFirewallRuleHeader {
param([hashtable]$Meta, [string]$EntityKey)
$text = if ($Meta[$EntityKey].nameResourceKey) { Get-LanguageString "SettingDetails.$($Meta[$EntityKey].nameResourceKey)" }
if ($text) { $text } else { $EntityKey }
}
# Option label(s) for a firewall rule value. Flag enums ('private,public') map
# each part and join them with the property separator.
function Get-DocumentationFirewallRuleOption {
param([hashtable]$Meta, [string]$EntityKey, $Value, [string]$Separator)
$labels = foreach ($part in ("$Value" -split ',')) {
$part = $part.Trim()
if (-not $part) { continue }
$option = @($Meta[$EntityKey].options) | Where-Object { "$($_.value)" -eq $part } | Select-Object -First 1
$text = if ($option.nameResourceKey) { Get-LanguageString "SettingDetails.$($option.nameResourceKey)" }
if ($text) { $text } else { $part }
}
return (@($labels) -join $Separator)
}
# Endpoint Protection firewall rules. The portal metadata marks the rules table and
# every column enabled=false (rules are edited in a separate pane), so SkipDisabled
# dropped the row, and the generic table walk left the synthetic columns
# (application, protocol, ports, addresses) empty. Emit one enabled row whose
# FullValueTable has a line per rule, keeping only the columns some rule sets.
function Add-DocumentationFirewallRules {
param($Obj, $Prop, [DocumentationContext]$Context)
$rowProp = [PSCustomObject]@{
nameResourceKey = 'firewallRules'
descriptionResourceKey = 'firewallCreateRules'
entityKey = $Prop.entityKey
dataType = $Prop.dataType
category = $Prop.category
enabled = $true
}
$rules = @($Obj."$($Prop.entityKey)" | Where-Object { $null -ne $_ })
if ($rules.Count -eq 0) {
Add-PropertyInfo $rowProp $null
return
}
# Column metadata by entityKey, including the port settings nested under the
# protocol options' children.
$meta = @{}
$pending = [System.Collections.Generic.Queue[object]]::new()
foreach ($column in @($Prop.columns)) { if ($column.metadata) { $pending.Enqueue($column.metadata) } }
while ($pending.Count -gt 0) {
$setting = $pending.Dequeue()
if ($setting.entityKey -and -not $meta.ContainsKey($setting.entityKey)) { $meta[$setting.entityKey] = $setting }
foreach ($option in @($setting.options)) {
foreach ($child in @($option.children)) { if ($child) { $pending.Enqueue($child) } }
}
}
$sep = $Context.PropertySeparator
$notConfigured = Get-LanguageString 'SettingDetails.notConfigured'
$appKey = 'firewallRuleSyntheticApplicationKey'
$protocolKey = 'firewallRuleSyntheticProtocolKey'
$columnKeys = @('displayName', 'description', 'trafficDirection', 'action', 'profileTypes', $appKey, $protocolKey,
'firewallRuleSyntheticLocalPortsKey', 'firewallRuleSyntheticRemotePortsKey',
'firewallRuleSyntheticLocalAddressesKey', 'firewallRuleSyntheticRemoteAddressesKey',
'interfaceTypes', 'localUserAuthorizations')
$usedKeys = @{ displayName = $true }
$ruleCells = @(foreach ($rule in $rules) {
$cells = @{ displayName = $rule.displayName; description = $rule.description; localUserAuthorizations = $rule.localUserAuthorizations }
if ($rule.description) { $usedKeys.description = $true }
if ($rule.localUserAuthorizations) { $usedKeys.localUserAuthorizations = $true }
foreach ($key in 'trafficDirection', 'action', 'profileTypes', 'interfaceTypes') {
if ($null -ne $rule.$key -and "$($rule.$key)" -notin @('', 'notConfigured')) {
$cells[$key] = Get-DocumentationFirewallRuleOption $meta $key $rule.$key $sep
$usedKeys[$key] = $true
}
else { $cells[$key] = $notConfigured }
}
# The application option values are the rule property names.
$apps = foreach ($appProp in 'packageFamilyName', 'filePath', 'serviceName') {
if ($rule.$appProp) { '{0}: {1}' -f (Get-DocumentationFirewallRuleOption $meta $appKey $appProp $sep), $rule.$appProp }
}
if (@($apps).Count -gt 0) { $cells[$appKey] = @($apps) -join $sep; $usedKeys[$appKey] = $true }
else { $cells[$appKey] = Get-DocumentationFirewallRuleOption $meta $appKey 'all' $sep }
# Graph stores the IANA protocol number; the portal offers Any / TCP (6) / UDP (17) / Custom.
$protocol = $rule.protocol
if ($null -eq $protocol) { $cells[$protocolKey] = Get-DocumentationFirewallRuleOption $meta $protocolKey 'any' $sep }
else {
$usedKeys[$protocolKey] = $true
$cells[$protocolKey] = if ($protocol -eq 6) { Get-DocumentationFirewallRuleOption $meta $protocolKey 'TCP' $sep }
elseif ($protocol -eq 17) { Get-DocumentationFirewallRuleOption $meta $protocolKey 'UDP' $sep }
else { '{0}: {1}' -f (Get-DocumentationFirewallRuleOption $meta $protocolKey 'customProtocol' $sep), $protocol }
}
# Ports only apply to TCP/UDP; addresses always default to "Any address".
foreach ($pair in @(@('firewallRuleSyntheticLocalPortsKey', 'localPortRanges', ($protocol -in 6, 17)),
@('firewallRuleSyntheticRemotePortsKey', 'remotePortRanges', ($protocol -in 6, 17)),
@('firewallRuleSyntheticLocalAddressesKey', 'localAddressRanges', $true),
@('firewallRuleSyntheticRemoteAddressesKey', 'remoteAddressRanges', $true))) {
$ranges = @($rule."$($pair[1])" | Where-Object { $_ })
if ($ranges.Count -gt 0) { $cells[$pair[0]] = $ranges -join $sep; $usedKeys[$pair[0]] = $true }
elseif ($pair[2]) { $cells[$pair[0]] = Get-DocumentationFirewallRuleOption $meta $pair[0] 'all' $sep }
else { $cells[$pair[0]] = '' }
}
$cells
})
$keys = @($columnKeys | Where-Object { $usedKeys[$_] })
$headers = @{}
foreach ($key in $keys) { $headers[$key] = Get-DocumentationFirewallRuleHeader $meta $key }
$table = foreach ($cells in $ruleCells) {
$row = [ordered]@{}
foreach ($key in $keys) { $row[$headers[$key]] = $cells[$key] }
[PSCustomObject]$row
}
$value = @(foreach ($cells in $ruleCells) { @(foreach ($key in $keys) { $cells[$key] }) -join $sep }) -join $Context.ObjectSeparator
Add-PropertyInfo $rowProp $value $rules -TableValue @($table)
}
function Initialize-FeatureUpdateSyntheticProperties {
param($Obj, [DocumentationContext]$Context)
@@ -1257,6 +1377,10 @@ function Get-DocumentationCustomProfileValue {
Invoke-TranslateOption $TopObj $Prop | Out-Null
return $false
}
if ($Prop.entityKey -eq 'firewallRules') {
Add-DocumentationFirewallRules $Obj $Prop $Context
return $false
}
}
if ($type -eq '#microsoft.graph.windowsHealthMonitoringConfiguration' -and $Prop.entityKey -eq 'configDeviceHealthMonitoringScope' -and ($Prop.options | Where-Object value -EQ 'healthMonitoring')) { return $false }
if ($type -eq '#microsoft.graph.windows10VpnConfiguration') {
@@ -1274,13 +1398,23 @@ function Get-DocumentationCustomProfileValue {
function Finalize-DocumentationCustomObject {
param($Obj, [DocumentationContext]$Context)
if ($Obj.'@odata.type' -ne '#microsoft.graph.windows10EndpointProtectionConfiguration') { return }
foreach ($categoryId in @('bitLocker','xboxServices')) {
# Drop a whole category when none of its rows differs from its default. Graph
# returns enum defaults for settings nobody touched (e.g. Xbox services 'manual',
# lanManagerAuthenticationLevel 'lmAndNltm') and the portal hides them. Done per
# category rather than per row: a default value is still shown when something
# else in its category is configured.
foreach ($categoryId in @('bitLocker','xboxServices','defenderLocalSecurityOptions')) {
$category = Get-LanguageString "Category.$categoryId"
if (-not $category) { continue }
$rows = @($Context.SettingsData | Where-Object Category -EQ $category)
$configured = $rows | Where-Object {
if ($categoryId -eq 'bitLocker' -and $_.EntityKey -like 'startupAuthenticationTpm*') { return $false }
return $null -ne $_.RawValue -and $_.RawValue -ne $_.DefaultValue
$raw = $_.RawValue
if ($null -eq $raw -or "$raw" -in @('', 'notConfigured')) { return $false }
if ($raw -is [array]) { return $raw.Count -gt 0 }
# String compare: -ne coerces to the left operand's type, so a boolean
# RawValue against a string default would compare as booleans.
return "$raw" -ne "$($_.DefaultValue)"
} | Select-Object -First 1
if ($configured) { continue }
foreach ($row in $rows) { [void]$Context.SettingsData.Remove($row) }
@@ -2,11 +2,331 @@
# handler.
#
# Claims @odata.type='#microsoft.graph.deviceManagementReusablePolicySetting'.
# Covers the reusable settings surfaced as policy types (currently the Linux
# custom-compliance discovery script). The object is a name + description +
# settingDefinitionId wrapper around a single settings-catalog setting
# instance whose simpleSettingValue carries the payload (base64 script for
# the discovery-script definition). No old-project documenter existed.
# A reusable setting is a name + description around ONE settings-catalog
# setting instance (settingInstance). The portal wizard
# (ReusableSettingsWizard.ReactView.js) reads that instance against the schema
# from deviceManagement/reusableSettings, which is where the display names of
# every child ("Keyword", "Auto Resolve", "Match type", "Device properties", ...)
# and of every choice option ("True", "Match all") live. The generic
# configurationSettings/{id} endpoint answers nothing for these ids (they carry
# {id} / {groupid} placeholders), so the schema is loaded from that list once
# per session and handed to the settings-catalog walker inline.
#
# Rendering: a list of items (GroupSettingCollection whose items hold only
# simple / choice values - firewall dynamic keyword addresses, Device Control
# device properties, printer devices) becomes one row with a table value
# (FullValueTable: one column per named child) plus a flat Value for the
# outputs that cannot show a table. Groups that nest further lists (the Device
# Control group itself) are flattened: their simple values become rows and
# their lists tables. Anything else is a plain Name = Value row, the Linux
# discovery script decoded.
#
# No schema reachable (fully offline): rows and choice values are named from
# the definition ids instead of showing nothing.
#
# The list endpoint omits settingInstance; the single GET with $select carries
# it (same contract as the export hydration in ReusableSettingsObjectBase).
# Documenting straight from the tenant therefore fetches it when the source
# tenant is available, and attaches it to the object so an export of the same
# run is complete.
$script:_docReusableSettingDefinitions = $null
function Reset-ReusableSettingDefinitionCache {
$script:_docReusableSettingDefinitions = $null
}
# All reusable-setting definitions (roots and children) as Graph returns them,
# loaded once per session. Generic schema, so gated on connectivity only, not
# on SourceTenantUnavailable - documenting an export while signed into another
# tenant still resolves names.
function Get-ReusableSettingDefinitions {
param([DocumentationContext]$Context)
if ($null -ne $script:_docReusableSettingDefinitions) { return $script:_docReusableSettingDefinitions }
if (-not (Test-DocumentationGraphAvailable)) { return @() }
try {
$resp = Invoke-MSGraphAPI -Url "/deviceManagement/reusableSettings" -ODataMetadata 'minimal' -AdditionalHeaders (Get-DocAcceptLanguageHeaders $Context)
$script:_docReusableSettingDefinitions = @($resp.value)
}
catch {
Write-LogError "Failed to fetch the reusable setting definitions" $_.Exception
$script:_docReusableSettingDefinitions = @()
}
return $script:_docReusableSettingDefinitions
}
# A readable name from a definition id when the schema did not give one:
# the part after the parent id ("..._{id}_autoresolve" -> "Autoresolve"), else
# the last segment that is not a {placeholder}.
function Get-ReusableSettingFallbackName {
param([string]$Id, [string]$ParentId)
if ([string]::IsNullOrEmpty($Id)) { return '' }
$tail = $Id
if ($ParentId -and $Id.StartsWith("$ParentId`_", [StringComparison]::OrdinalIgnoreCase) -and $Id.Length -gt $ParentId.Length + 1) {
$tail = $Id.Substring($ParentId.Length + 1)
}
else {
$segments = @($Id.Split('_') | Where-Object { $_ -and $_ -notmatch '^\{.*\}$' })
if ($segments.Count -gt 0) { $tail = $segments[-1] }
}
$tail = $tail.Replace('_', ' ').Trim()
if ($tail.Length -eq 0) { return '' }
return $tail.Substring(0, 1).ToUpperInvariant() + $tail.Substring(1)
}
# Row name: the schema display name; derived from the id only when no schema
# resolved the row at all. A schema row with a BLANK name is one Microsoft
# hides (the GUID id of a firewall address) and stays blank, so callers skip it.
function Get-ReusableSettingRowName {
param($Row, [string]$ParentId, [object[]]$Definitions)
$name = [string]$Row.Name
if (-not [string]::IsNullOrWhiteSpace($name)) { return $name.Trim() }
if ($Definitions -and $Row.SettingId -and ($Definitions | Where-Object id -EQ $Row.SettingId | Select-Object -First 1)) { return '' }
return Get-ReusableSettingFallbackName $Row.SettingId $ParentId
}
# Value of a simple / choice row: what the walker resolved, else - for a choice
# whose option the schema did not name - the option suffix ("..._true" -> "True").
function Get-ReusableSettingRowValue {
param($Row)
$value = $Row.Value
if ($null -eq $value -or ([string]$value).Length -eq 0) {
$raw = [string]$Row.RawValue
if ($raw -and $Row.SettingId -and $Row.Type -like '*ChoiceSettingInstance') {
$value = Get-ReusableSettingFallbackName $raw $Row.SettingId
}
elseif ($raw) { $value = $raw }
}
if ($value -is [string] -and [string]$Row.SettingId -like '*discoveryscript*') {
# The discovery-script definition stores the script base64-encoded.
try {
$decoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($value))
if ($decoded) { $value = $decoded }
}
catch { }
}
return $value
}
# True when a walker node is a list or group container.
function Test-ReusableSettingGroupNode {
param($Row)
return ([string]$Row.Type -like '*GroupSettingCollectionInstance' -or [string]$Row.Type -like '*GroupSettingInstance')
}
# Emit the documentation rows for one walker node (and what it contains).
function ConvertTo-ReusableSettingDocRows {
param(
$Node,
[DocumentationContext]$Context,
[string]$ParentId,
[int]$Level = 0,
[object[]]$Definitions = @()
)
if (-not $Node) { return }
$type = [string]$Node.Type
if ($type -like '*GroupSettingCollectionInstance') {
$items = @($Node.ChildSettings)
$nested = $false
foreach ($item in $items) {
foreach ($child in @($item.Settings)) {
if (Test-ReusableSettingGroupNode $child) { $nested = $true; break }
}
if ($nested) { break }
}
if ($nested -or $items.Count -eq 0) {
# A group of groups: its simple values become rows and its lists tables.
foreach ($item in $items) {
foreach ($child in @($item.Settings)) {
ConvertTo-ReusableSettingDocRows -Node $child -Context $Context -ParentId $Node.SettingId -Level $Level -Definitions $Definitions
}
}
return
}
# A list of flat items: one table, a column per named child (schema
# order, first appearance), rows in item order.
$columns = [System.Collections.Generic.List[string]]::new()
$tableRows = @()
$flatItems = @()
foreach ($item in $items) {
$cells = [ordered]@{}
$parts = @()
foreach ($child in @($item.Settings)) {
$colName = Get-ReusableSettingRowName $child $Node.SettingId $Definitions
if ([string]::IsNullOrEmpty($colName)) { continue } # the unnamed GUID id of a firewall address
if (-not $columns.Contains($colName)) { [void]$columns.Add($colName) }
$cellValue = [string](Get-ReusableSettingRowValue $child)
$cells[$colName] = $cellValue
if ($cellValue.Length -gt 0) { $parts += "${colName}: $cellValue" }
}
$tableRows += ,$cells
$flatItems += ($parts -join $Context.PropertySeparator)
}
$table = foreach ($cells in $tableRows) {
$rowObj = [ordered]@{}
foreach ($col in $columns) { $rowObj[$col] = if ($cells.Contains($col)) { $cells[$col] } else { '' } }
[PSCustomObject]$rowObj
}
$label = Get-ReusableSettingRowName $Node $ParentId $Definitions
# Microsoft named the firewall list root " Id"; the category (Firewall)
# is the readable label there.
if ([string]::IsNullOrWhiteSpace($label) -or $label -eq 'Id') { $label = [string]$Node.Category }
if ([string]::IsNullOrWhiteSpace($label)) { $label = Get-ReusableSettingFallbackName $Node.SettingId $null }
$Context.AddSetting([PSCustomObject]@{
Name = $label
Value = ($flatItems -join $Context.ObjectSeparator)
Description = $Node.Description
Category = $Node.Category
SubCategory = $Node.SubCategory
Level = $Level
SettingId = $Node.SettingId
RowIndex = $Node.RowIndex
RawValue = $Node.RawJsonValue
RawJsonValue = $Node.RawJsonValue
FullValueTable = @($table)
})
return
}
if ($type -like '*GroupSettingInstance') {
foreach ($child in @($Node.ChildSettings)) {
ConvertTo-ReusableSettingDocRows -Node $child -Context $Context -ParentId $Node.SettingId -Level $Level -Definitions $Definitions
}
return
}
$rowName = Get-ReusableSettingRowName $Node $ParentId $Definitions
if ([string]::IsNullOrEmpty($rowName)) { return } # hidden by the schema
$Context.AddSetting([PSCustomObject]@{
Name = $rowName
Value = (Get-ReusableSettingRowValue $Node)
Description = $Node.Description
Category = $Node.Category
SubCategory = $Node.SubCategory
Level = $Level
SettingId = $Node.SettingId
RowIndex = $Node.RowIndex
RawValue = $Node.RawValue
RawJsonValue = $Node.RawJsonValue
DefaultValue = $Node.DefaultValue
})
# A choice can carry dependent children.
foreach ($child in @($Node.ChildSettings)) {
if ($child -and $child.PSObject.Properties['SettingId']) {
ConvertTo-ReusableSettingDocRows -Node $child -Context $Context -ParentId $Node.SettingId -Level ($Level + 1) -Definitions $Definitions
}
}
}
# The setting instance: from the object, else from the source tenant (the list
# endpoint leaves it out). Attached to the object so an export of the same run
# carries it.
function Get-ReusableSettingInstance {
param($PolicyObject, [DocumentationContext]$Context)
$obj = $PolicyObject.JsonObject
if ($obj.settingInstance) { return $obj.settingInstance }
if (-not $obj.id -or $Context.SourceTenantUnavailable -or -not (Test-DocumentationGraphAvailable)) { return $null }
try {
# minimal, not none: with none Graph drops the @odata.type of every
# setting instance, and the walker cannot tell a list from a value.
$live = Invoke-MSGraphAPI -Url "/deviceManagement/reusablePolicySettings/$($obj.id)?`$select=settinginstance,displayname,description" -ODataMetadata 'minimal' -NoError
if ($live -and $live.settingInstance) {
Add-Member -InputObject $obj -MemberType NoteProperty -Name 'settingInstance' -Value $live.settingInstance -Force
return $live.settingInstance
}
Write-Log "Reusable setting '$($PolicyObject.Name)' ($($obj.id)) returned no settingInstance" 2
}
catch {
Write-LogError "Failed to fetch the setting instance of reusable setting '$($PolicyObject.Name)'" $_.Exception
}
return $null
}
# The configuration-categories list carries only ordinary categories; one that
# exists for reusable settings alone (Device Control) is reachable by id only.
# Fetch it once and add it to the session cache, so both the Type row and the
# walker's row categories resolve.
function Resolve-ReusableSettingCategory {
param([string]$CategoryId, [DocumentationContext]$Context)
if ([string]::IsNullOrEmpty($CategoryId)) { return }
if ($Context.CfgCategories | Where-Object id -EQ $CategoryId | Select-Object -First 1) { return }
if (-not (Test-DocumentationGraphAvailable)) { return }
try {
$cat = Invoke-MSGraphAPI -Url "/deviceManagement/configurationCategories/$CategoryId" -ODataMetadata 'minimal' -AdditionalHeaders (Get-DocAcceptLanguageHeaders $Context) -NoError
if ($cat -and $cat.id) {
$Context.CfgCategories += @($cat)
Set-CacheObject "CfgCategories" $Context.CfgCategories -Persistent
}
}
catch {
Write-LogError "Failed to fetch configuration category $CategoryId" $_.Exception
}
}
# What kind of reusable setting this is, for the basic info: the category of
# the root definition (Firewall, Device Control), else the definition's own
# name (Script), else derived from the id.
function Get-ReusableSettingTypeName {
param($RootDefinition, [string]$DefinitionId, [DocumentationContext]$Context)
if ($RootDefinition -and $RootDefinition.categoryId) {
$cat = $Context.CfgCategories | Where-Object id -EQ $RootDefinition.categoryId | Select-Object -First 1
if ($cat -and -not [string]::IsNullOrWhiteSpace([string]$cat.displayName)) { return [string]$cat.displayName }
}
$name = if ($RootDefinition) { ([string]$RootDefinition.displayName).Trim() } else { '' }
if (-not [string]::IsNullOrWhiteSpace($name) -and $name -ne 'Id') { return $name }
return Get-ReusableSettingFallbackName $DefinitionId $null
}
function Invoke-DocReusableSetting {
param($PolicyObject, [DocumentationContext]$Context)
$obj = $PolicyObject.JsonObject
if ($PolicyObject.Name) {
Add-BasicPropertyValue (Get-LanguageString 'SettingDetails.nameName') $PolicyObject.Name 'displayName'
}
$descValue = if ($obj.description) { $obj.description } else { '' }
Add-BasicPropertyValue (Get-LanguageString 'SettingDetails.descriptionName') $descValue 'description'
Initialize-SettingsCatalogSchemaCache $Context
$definitions = @(Get-ReusableSettingDefinitions $Context)
$rootDef = $null
if ($obj.settingDefinitionId) {
$rootDef = $definitions | Where-Object id -EQ $obj.settingDefinitionId | Select-Object -First 1
if ($rootDef) { Resolve-ReusableSettingCategory ([string]$rootDef.categoryId) $Context }
Add-BasicPropertyValue (Get-LanguageString 'TableHeaders.type') (Get-ReusableSettingTypeName $rootDef ([string]$obj.settingDefinitionId) $Context) 'settingDefinitionId'
}
Add-BasicAdditionalValues $PolicyObject # created / modified / version
$instance = Get-ReusableSettingInstance $PolicyObject $Context
if (-not $instance) { return }
if ($Context.Options -and $Context.Options['IncludeScripts'] -eq $false -and [string]$obj.settingDefinitionId -like '*script*') { return }
# The walker resolves names, options and categories from the inline
# definitions; its buffer is not used, the returned tree is.
Reset-SettingsCatalogPolicyBuffer
$root = Add-SettingsSetting $instance $definitions
Reset-SettingsCatalogPolicyBuffer
if (-not $root) { return }
ConvertTo-ReusableSettingDocRows -Node $root -Context $Context -ParentId $null -Level 0 -Definitions $definitions
}
class ReusableSettingDocHandler : DocumentationHandlerBase {
ReusableSettingDocHandler() {
@@ -14,54 +334,7 @@ class ReusableSettingDocHandler : DocumentationHandlerBase {
}
[void] Document([object]$PolicyObject, [DocumentationContext]$Context) {
$obj = $PolicyObject.JsonObject
if ($PolicyObject.Name) {
Add-BasicPropertyValue (Get-LanguageString 'SettingDetails.nameName') $PolicyObject.Name 'displayName'
}
$descValue = if ($obj.description) { $obj.description } else { '' }
Add-BasicPropertyValue (Get-LanguageString 'SettingDetails.descriptionName') $descValue 'description'
$category = Get-LanguageString 'TableHeaders.settings'
if ($obj.settingDefinitionId) {
$definitionLabel = Get-LanguageString 'SettingDetails.settingIdName' -IgnoreMissing
if (-not $definitionLabel) { $definitionLabel = 'Setting definition' }
Add-CustomSettingObject ([PSCustomObject]@{
Name = $definitionLabel
Value = [string]$obj.settingDefinitionId
EntityKey = 'settingDefinitionId'
Category = $category
SubCategory = $null
})
}
$rawValue = [string]$obj.settingInstance.simpleSettingValue.value
if ($rawValue -and -not ($Context.Options -and $Context.Options['IncludeScripts'] -eq $false)) {
# The discovery-script definition stores the script base64-encoded;
# fall back to the raw value for definitions that don't.
$value = $rawValue
try {
$decoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($rawValue))
if ($decoded) { $value = $decoded }
}
catch { }
$valueLabel = if ([string]$obj.settingDefinitionId -like '*discoveryscript*') {
Get-LanguageString 'ProactiveRemediations.Create.Settings.DetectionScriptMultiLineTextBox.label'
}
else {
$lbl = Get-LanguageString 'SettingDetails.valueName' -IgnoreMissing
if ($lbl) { $lbl } else { 'Value' }
}
Add-CustomSettingObject ([PSCustomObject]@{
Name = $valueLabel
Value = $value
EntityKey = 'settingInstanceValue'
Category = $category
SubCategory = $null
})
}
Invoke-DocReusableSetting $PolicyObject $Context
}
}