This commit is contained in:
Mikael Karlsson
2023-01-26 22:29:21 +11:00
parent 897309e48e
commit ece28a649f
41 changed files with 6475 additions and 1894 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -10,7 +10,7 @@ This module will also document some objects based on PowerShell functions
function Get-ModuleVersion
{
'1.4.0'
'1.5.0'
}
function Invoke-InitializeModule
@@ -27,6 +27,7 @@ function Invoke-InitializeModule
PostAddValue = { Invoke-CDDocumentCustomPostAdd @args }
ObjectDocumented = { Invoke-CDDocumentCustomObjectDocumented @args }
TranslateSectionFile = { Invoke-CDDocumentTranslateSectionFile @args }
PostSettingsCatalog = { Invoke-CDDocumentPostSettingsCatalog @args }
})
}
@@ -150,11 +151,16 @@ function Invoke-CDDocumentObject
}
elseif($type -eq '#microsoft.graph.deviceComplianceScript')
{
Invoke-CDDocumentdeviceComplianceScript $documentationObj
Invoke-CDDocumentDeviceComplianceScript $documentationObj
return [PSCustomObject]@{
Properties = @("Name","Value","Category","SubCategory")
}
}
}
elseif($type -eq '#microsoft.graph.roleScopeTag')
{
Invoke-CDDocumentScopeTag $documentationObj
return $true
}
}
function Get-CDAllManagedApps
@@ -810,7 +816,13 @@ function Add-CDDocumentCustomProfileProperty
$obj.outOfBoxExperienceSettings | Add-Member Noteproperty -Name "azureADJoinType" -Value $joinType
$obj.outOfBoxExperienceSettings | Add-Member Noteproperty -Name "isLanguageSet" -Value (?: ([String]::IsNullOrEmpty($obj.language)) $false $true)
$obj.outOfBoxExperienceSettings | Add-Member Noteproperty -Name "isLanguageSet" -Value (?: ([String]::IsNullOrEmpty($obj.language)) $false $true)
if([String]::IsNullOrEmpty($obj.language))
{
$obj.language = "user-select"
}
$retValue = $true
}
elseif($obj.'@OData.Type' -eq "#microsoft.graph.officeSuiteApp")
@@ -1188,7 +1200,11 @@ function Add-CDDocumentCustomProfileProperty
$returnCodes = @()
foreach($rc in $obj.returnCodes)
{
$returnCodes += ("{0} {1}" -f @($rc.returnCode,(Get-LanguageString "Win32ReturnCodes.CodeTypes.$($rc.type)")))
$returnCodes += [PSCustomObject]@{
returnCode = $rc.returnCode
type = (Get-LanguageString "Win32ReturnCodes.CodeTypes.$($rc.type)")
}
#$returnCodes += ("{0} {1}" -f @($rc.returnCode,(Get-LanguageString "Win32ReturnCodes.CodeTypes.$($rc.type)")))
}
$dependencyApps = @()
@@ -1226,6 +1242,7 @@ function Add-CDDocumentCustomProfileProperty
{
$lngId = "script"
$textValue = $rule.displayName
Add-ObjectScript $rule.displayName ("{0} - {1}" -f @($obj.displayName, "Requirement script")) $rule.ScriptContent
}
$requirementRulesSummary += ("{0} {1}" -f @((Get-LanguageString "Win32Requirements.AdditionalRequirements.RequirementTypeOptions.$lngId"),$textValue))
}
@@ -1233,6 +1250,11 @@ function Add-CDDocumentCustomProfileProperty
if(($obj.detectionRules | Where '@OData.Type' -eq "#microsoft.graph.win32LobAppPowerShellScriptDetection"))
{
$detectionRulesType = Get-LanguageString "DetectionRules.RuleConfigurationOptions.customScript"
foreach($rule in $obj.detectionRules)
{
$header = (Get-LanguageString "ProactiveRemediations.Create.Settings.DetectionScriptMultiLineTextBox.label")
Add-ObjectScript $header ("{0} - {1}" -f @($obj.displayName,$header)) $rule.ScriptContent
}
}
else
{
@@ -1257,12 +1279,13 @@ function Add-CDDocumentCustomProfileProperty
$detectionRulesSummary += ("{0} {1}" -f @((Get-LanguageString "DetectionRules.Manual.RuleTypeOptions.$lngId"),$textValue))
}
}
$obj | Add-Member Noteproperty -Name "requirementRulesSummary" -Value ($requirementRulesSummary -join $objSeparator) -Force
$obj | Add-Member Noteproperty -Name "detectionRulesSummary" -Value ($detectionRulesSummary -join $objSeparator) -Force
$obj | Add-Member Noteproperty -Name "dependencyApps" -Value ($dependencyApps -join $objSeparator) -Force
$obj | Add-Member Noteproperty -Name "supersededApps" -Value ($supersededApps -join $objSeparator) -Force
$obj | Add-Member Noteproperty -Name "detectionRulesType" -Value $detectionRulesType -Force
$obj | Add-Member Noteproperty -Name "returnCodes" -Value ($returnCodes -join $objSeparator) -Force
$obj | Add-Member Noteproperty -Name "returnCodes" -Value $returnCodes -Force
$obj | Add-Member Noteproperty -Name "win10Release" -Value (Get-LanguageString "MinimumOperatingSystem.Windows.V10Release.release$($obj.minimumSupportedWindowsRelease)") -Force
}
elseif($obj.'@OData.Type' -eq "#microsoft.graph.deviceHealthScript")
@@ -1274,12 +1297,29 @@ function Add-CDDocumentCustomProfileProperty
if($obj.detectionScriptContent)
{
$obj | Add-Member Noteproperty -Name "detectionScriptContentString" -Value ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String(($obj.detectionScriptContent))))
$header = Get-LanguageString "ProactiveRemediations.Create.Settings.DetectionScriptMultiLineTextBox.label"
Add-ObjectScript $header ("{1} - {0}" -f $obj.displayName,$header) $obj.detectionScriptContent
}
if($obj.remediationScriptContent)
{
$obj | Add-Member Noteproperty -Name "remediationScriptContentString" -Value ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String(($obj.remediationScriptContent))))
$header = Get-LanguageString "ProactiveRemediations.Create.Settings.RemediationScriptMultiLineTextBox.label"
Add-ObjectScript $header ("{1} - {0}" -f $obj.displayName,$header) $obj.remediationScriptContent
}
}
elseif($obj.'@OData.Type' -eq "#microsoft.graph.deviceManagementScript")
{
if($obj.ScriptContent)
{
Add-ObjectScript $obj.FileName ("{1} - {0}" -f $obj.displayName,(Get-LanguageString "WindowsManagement.powerShellScriptObjectName")) $obj.ScriptContent
}
}
elseif($obj.'@OData.Type' -eq "#microsoft.graph.deviceShellScript")
{
if($obj.ScriptContent)
{
Add-ObjectScript $obj.FileName ("{1} - {0}" -f $obj.displayName,(Get-LanguageString "WindowsManagement.shellScriptObjectName")) $rule.ScriptContent
}
}
elseif($obj.'@OData.Type' -eq "#microsoft.graph.windows10TeamGeneralConfiguration")
{
@@ -1313,6 +1353,13 @@ function Add-CDDocumentCustomProfileProperty
$obj | Add-Member Noteproperty -Name "hasForceRestart" -Value $true
}
}
elseif($obj.'@OData.Type' -like "#microsoft.graph.windowsWifiConfiguration")
{
if($obj.wifiSecurityType -eq "wpa2Personal")
{
$obj.preSharedKey = "********"
}
}
if(($obj.PSObject.Properties | where Name -eq "securityRequireSafetyNetAttestationBasicIntegrity") -and
($obj.PSObject.Properties | where Name -eq "securityRequireSafetyNetAttestationCertifiedDevice"))
@@ -1332,6 +1379,7 @@ function Add-CDDocumentCustomProfileProperty
$retValue = $true
}
if(($obj.PSObject.Properties | Where Name -eq "periodOfflineBeforeWipeIsEnforced"))
{
#Conditional Launch settings for AppProtection policies
@@ -3851,7 +3899,7 @@ function Invoke-CDDocumentTranslateSectionFile
#endregion
#region
function Invoke-CDDocumentdeviceComplianceScript
function Invoke-CDDocumentDeviceComplianceScript
{
param($documentationObj)
@@ -3914,4 +3962,70 @@ function Invoke-CDDocumentdeviceComplianceScript
SubCategory = $null
})
}
#endregion
#region Settings Catalog
function Invoke-CDDocumentPostSettingsCatalog
{
param($obj, $objectType, $settingsData)
if($obj.templateReference.TemplateId.StartsWith("19c8aa67-f286-4861-9aa0-f23541d31680"))
{
$reusableSettingsType = Get-GraphObjectType "ReusableSettings"
if($reusableSettingsType)
{
foreach($setting in ($settingsData | Where SettingId -eq "vendor_msft_firewall_mdmstore_firewallrules_{firewallrulename}_remoteaddressdynamickeywords"))
{
$reusableSettings = Invoke-GraphRequest -Url "$($reusableSettingsType.API)/$($setting.RawValue)"
if($reusableSettings.displayName)
{
$setting.Value = $reusableSettings.displayName
}
else
{
Write-Log "No Reusable Settings object found with ID $($setting.RawValue)" 2
}
}
}
}
}
#endregion
#region Scope Tags
function Invoke-CDDocumentScopeTag
{
param($obj, $objectType)
$script:objectSeparator = ?? $global:cbDocumentationObjectSeparator.SelectedValue ([System.Environment]::NewLine)
$script:propertySeparator = ?? $global:cbDocumentationPropertySeparator.SelectedValue ","
$groupIDs, $groupInfo, $filterIds,$filtersInfo = Get-ObjectAssignments $obj.Object
$nameLabel = Get-LanguageString "Inputs.displayNameLabel"
$descriptionLabel = Get-LanguageString "TableHeaders.description"
$assignmentsLabel = Get-LanguageString "TableHeaders.assignments"
$scopeTagInfo = Get-TableObjects $obj.ObjectType
if(-not $scopeTagInfo)
{
$scopeTagInfo = [PSCustomObject]@{
TypeName = (Get-LanguageString "SettingDetails.scopeTags")
ObjectType = $obj.ObjectType
Properties = @($nameLabel, "id", $descriptionLable, $assignmentsLabel)
Items = @()
}
Set-TableObjects $scopeTagInfo
}
$scopeTagInfo.Items += ([PSCustomObject]@{
$nameLabel = $obj.displayName
ID = $obj.Id
$descriptionLabel = $obj.Description
$assignmentsLabel = ($groupInfo.displayName -join $script:objectSeparator)
Object = $documentationObj.Object
})
}
#endregion

View File

@@ -0,0 +1,657 @@
function Get-ModuleVersion
{
'1.0.0'
}
function Invoke-InitializeModule
{
Add-OutputType ([PSCustomObject]@{
Name="HTML"
Value="html"
OutputOptions = (Add-HTMLOptionsControl)
#Activate = { Invoke-HTMLActivate @args }
PreProcess = { Invoke-HTMLPreProcessItems @args }
NewObjectGroup = { Invoke-HTMLNewObjectGroup2 @args }
NewObjectType = { Invoke-HTMLNewObjectType2 @args }
Process = { Invoke-HTMLProcessItem @args }
PostProcess = { Invoke-HTMLPostProcessItems @args }
ProcessAllObjects = { Invoke-HTMLProcessAllObjects @args }
})
}
function Add-HTMLOptionsControl
{
$script:htmlForm = Get-XamlObject ($global:AppRootFolder + "\Xaml\DocumentationHTMLOptions.xaml") -AddVariables
Set-XamlProperty $script:htmlForm "cbHTMLDocumentOutputFile" "ItemsSource" ("[ { Name: `"Single file`",Value: `"Full`" }, { Name: `"One file per object`",Value: `"Object`" }]" | ConvertFrom-Json)
Set-XamlProperty $script:htmlForm "cbHTMLDocumentOutputFile" "SelectedValue" (Get-Setting "Documentation" "HTMLDocumentFileType" "Full")
Set-XamlProperty $script:htmlForm "chkHTMLOpenDocument" "IsChecked" (Get-Setting "Documentation" "HTMLOpenFile" $true)
Set-XamlProperty $script:htmlForm "txtHTMLDocumentName" "Text" (Get-Setting "Documentation" "HTMLDocumentName" "")
Set-XamlProperty $script:htmlForm "txtHTMLCSSFile" "Text" (Get-Setting "Documentation" "HTMLCSSFile" "")
Add-XamlEvent $script:htmlForm "browseHTMLDocumentName" "add_click" {
$sf = [System.Windows.Forms.SaveFileDialog]::new()
$sf.DefaultExt = "*.html"
$sf.Filter = "HTML (*.html)|*.html|All files (*.*)|*.*"
if($sf.ShowDialog() -eq "OK")
{
Set-XamlProperty $script:htmlForm "txtHTMLDocumentName" "Text" $sf.FileName
Save-Setting "Documentation" "HTMLDocumentName" $sf.FileName
}
}
Add-XamlEvent $script:htmlForm "browseHTMLCSSFile" "add_click" {
$of = [System.Windows.Forms.OpenFileDialog]::new()
$of.Multiselect = $false
$of.Filter = "CSS Files (*.css)|*.css|All files (*.*)|*.*"
if($of.ShowDialog())
{
Set-XamlProperty $script:htmlForm "txtHTMLCSSFile" "Text" $of.FileName
Save-Setting "Documentation" "HTMLCSSFile" $of.FileName
}
}
$script:htmlForm
}
function Invoke-HTMLPreProcessItems
{
$script:sectionAnchors = @()
$script:totAnchors = @()
$script:htmlStrings = $null
$script:currentItemFileName = $null
Save-Setting "Documentation" "HTMLDocumentName" (Get-XamlProperty $script:htmlForm "txtHTMLDocumentName" "Text" "")
Save-Setting "Documentation" "HTMLCSSFile" (Get-XamlProperty $script:htmlForm "txtHTMLCSSFile" "Text" "")
Save-Setting "Documentation" "HTMLOpenFile" (Get-XamlProperty $script:htmlForm "chkHTMLOpenDocument" "IsChecked")
Save-Setting "Documentation" "HTMLDocumentFileType" (Get-XamlProperty $script:htmlForm "cbHTMLDocumentOutputFile" "SelectedValue" '')
$defaultCSSFile = $global:AppRootFolder + "\Documentation\DefaultHTMLStyle.css"
$HTMLCssFile = Get-XamlProperty $script:htmlForm "txtHTMLCSSFile" "Text" $defaultCSSFile
if(-not $HTMLCssFile)
{
Write-Log "CSS file not specified. Using default" 2
$HTMLCssFile = $defaultCSSFile
}
elseif([IO.File]::Exists($HTMLCssFile) -eq -$false)
{
Write-Log "CSS file $($HTMLCssFile) not found. Using default" 2
$HTMLCssFile = $defaultCSSFile
}
$cssStyle = ""
if([IO.File]::Exists($HTMLCssFile))
{
Write-Log "Using CSS file $($HTMLCssFile)"
$cssStyle = ((Get-Content -Raw -Path $HTMLCssFile) + [System.Environment]::NewLine)
}
else
{
Write-Log "CSS file $($HTMLCssFile) not found. No styles applied" 2
}
$script:cssStyle = $cssStyle
$fileName = Expand-FileName (Get-XamlProperty $script:htmlForm "txtHTMLDocumentName" "Text" "%MyDocuments%\%Organization%-%Date%.html")
$script:outFile = $fileName
$script:documentPath = [io.path]::GetDirectoryName($fileName)
$script:outputType = (Get-XamlProperty $script:htmlForm "cbHTMLDocumentOutputFile" "SelectedValue" "Full")
if($script:outputType -eq "Object")
{
Write-Log "Document one file for each object + index file"
}
else
{
Write-Log "Document one single file for all objects"
$script:outputType = "Full"
$script:htmlStrings = [System.Text.StringBuilder]::new()
}
}
function Invoke-HTMLPostProcessItems
{
$userName = $global:me.displayName
if($global:me.givenName -and $global:me.surname)
{
$userName = ($global:me.givenName + " " + $global:me.surname)
}
$script:htmlContent = [System.Text.StringBuilder]::new()
$script:htmlContent.AppendLine("<HTML>")
$script:htmlContent.AppendLine($script:cssStyle)
$script:htmlContent.AppendLine("<H1 class='header-level1'>$((?? $script:htmlDocTitle "Intune documentation"))</H1>")
$mail = ""
if($global:me.mail)
{
$mail = " ($($global:me.mail))"
}
$script:htmlContent.AppendLine("Organization: $($global:Organization.displayName)<br />")
$script:htmlContent.AppendLine("Generated by: $userName$mail<br />")
$script:htmlContent.AppendLine("Generated: $((Get-Date).ToShortDateString()) $((Get-Date).ToLongTimeString())<br />")
if($script:sectionAnchors.Count -gt 0)
{
$script:htmlContent.AppendLine("<br />")
$script:htmlContent.AppendLine("<H2 class='header-level2'>Table of Contents</H2>")
}
$tocMaxLevel = 4
foreach($header in $script:sectionAnchors)
{
if($tocMaxLevel -gt 0 -and $header.Level -gt $tocMaxLevel)
{
continue
}
$script:htmlContent.AppendLine("<a href='$($header.FileName)#$($header.Anchor)' class='anchor-style anchor-level$($header.Level)'>$($header.Name)</a><br />")
}
if($script:sectionAnchors.Count -gt 0)
{
$script:htmlContent.AppendLine("<br />")
}
$htmlText = $script:htmlContent.ToString()
if($script:outputType -eq "Full")
{
$htmlText += $script:htmlStrings.ToString()
}
$htmlText += "</HTML>"
Save-DocumentationFile $htmlText $script:outFile -OpenFile:((Get-Setting "Documentation" "HTMLOpenFile" $true) -eq $true)
}
function Invoke-HTMLNewObjectGroup
{
param($obj, $documentedObj)
$script:objectHeaderLevel = 2
$objectTypeString = Get-ObjectTypeString $obj.Object $obj.ObjectType
Add-HTMLHeader (?? $objectTypeString $obj.ObjectType.Title)
}
function Invoke-HTMLNewObjectType
{
param($obj, $documentedObj, [int]$groupCategoryCount = 0)
$script:objectHeaderLevel = 3
if($obj.ObjectType.GroupId -eq "EndpointSecurity")
{
$objectTypeString = $obj.CategoryName
}
else
{
$objectTypeString = $obj.ObjectType.Title
}
Add-HTMLHeader (?? $objectTypeString $obj.ObjectType.Title)
$script:objectHeaderLevel = 4
}
function Invoke-HTMLNewObjectGroup2
{
param($groupId)
$script:objectHeaderLevel = 2
$objectTypeString = Get-ObjectTypeString -ObjectType $groupId
Add-HTMLHeader (?? $objectTypeString $obj.ObjectType.Title)
}
function Invoke-HTMLNewObjectType2
{
param($objectTypeName)
$script:objectHeaderLevel = 3
Add-HTMLHeader $objectTypeName
$script:objectHeaderLevel = 4
}
function Add-HTMLHeader
{
param ($headerText, [int]$level = $script:objectHeaderLevel, [switch]$ToT, [switch]$SkipTOC)
if($script:htmlStrings)
{
$prefix = ""
if($ToT -eq $true)
{
$prefix = "Table $(($script:totAnchors.Count + 1)). "
}
if($ToT -eq $true)
{
$sectionAnchor = "table-$(($script:totAnchors.Count + 1))"
}
else
{
$sectionAnchor = "section-$(($script:sectionAnchors.Count + 1))"
}
$script:htmlStrings.AppendLine("<H$($level) id=`"$prefix$($sectionAnchor)`" class='header-level$($level)'>$headerText</H$($level)>")
$FileName = $script:currentItemFileName
}
else
{
$sectionAnchor = $null
$FileName = $null
}
if($ToT -eq $true)
{
$script:totAnchors += [PSCustomObject]@{
Name = $headerText
Anchor = $sectionAnchor
Level = $level
FileName = $FileName
}
}
elseif($SkipTOC -ne $true)
{
$script:sectionAnchors += [PSCustomObject]@{
Name = $headerText
Anchor = $sectionAnchor
Level = $level
FileName = $FileName
}
}
}
function Invoke-HTMLProcessItem
{
param($obj, $objectType, $documentedObj)
if(!$documentedObj -or !$obj -or !$objectType) { return }
$objName = Get-GraphObjectName $obj $objectType
if($script:outputType -eq "Object")
{
$script:totAnchors = @()
$script:htmlStrings = [System.Text.StringBuilder]::new()
$script:currentItemFileName = (Remove-InvalidFileNameChars "$($objName).html")
}
Add-HTMLHeader $objName
$script:htmlStrings.AppendLine("<br />")
try
{
foreach($tableType in @("BasicInfo","FilteredSettings"))
{
if($tableType -eq "BasicInfo")
{
$properties = @("Name","Value")
}
elseif($global:txtHTMLDocumentationProperties.SelectedValue -eq 'extended' -and $documentedObj.DisplayProperties)
{
$properties = @("Name","Value","Description")
}
elseif($global:txtHTMLDocumentationProperties.SelectedValue -eq 'custom' -and $global:txtHTMLCustomProperties.Text)
{
$properties = @()
foreach($prop in $global:txtHTMLCustomProperties.Text.Split(","))
{
# This will add language support for custom columens (or replacing existing header)
$propInfo = $prop.Split('=')
if(($propInfo | measure).Count -gt 1)
{
$properties += $propInfo[0]
Set-DocColumnHeaderLanguageId $propInfo[0] $propInfo[1]
}
else
{
$properties += $prop
}
}
}
else
{
$properties = (?? $documentedObj.DefaultDocumentationProperties (@("Name","Value")))
}
$lngId = ?: ($tableType -eq "BasicInfo") "SettingDetails.basics" "TableHeaders.settings" -AddCategories
Add-HTMLTableItems $obj $objectType ($documentedObj.$tableType) $properties $lngId -AddCategories -AddSubcategories
}
if(($documentedObj.ComplianceActions | measure).Count -gt 0)
{
$properties = @("Action","Schedule","MessageTemplate","EmailCC")
Add-HTMLTableItems $obj $objectType $documentedObj.ComplianceActions $properties "Category.complianceActionsLabel"
}
if(($documentedObj.ApplicabilityRules | measure).Count -gt 0)
{
$properties = @("Rule","Property","Value")
Add-HTMLTableItems $obj $objectType $documentedObj.ApplicabilityRules $properties "SettingDetails.applicabilityRules"
}
Add-HTMLObjectSettings $obj $objectType $documentedObj
if(($documentedObj.Assignments | measure).Count -gt 0)
{
if($documentedObj.Assignments[0].RawIntent)
{
$properties = @("GroupMode","Group","Filter","FilterMode")
$settingsObj = $documentedObj.Assignments | Where { $_.Settings -ne $null } | Select -First 1
if($settingsObj)
{
foreach($objProp in $settingsObj.Settings.Keys)
{
if($objProp -in $properties) { continue }
if($objProp -in @("Category","RawIntent")) { continue }
$properties += ("Settings." + $objProp)
}
}
}
else
{
$isFilterAssignment = $false
foreach($assignment in $documentedObj.Assignments)
{
if(($assignment.target.PSObject.Properties | Where Name -eq "deviceAndAppManagementAssignmentFilterType"))
{
$isFilterAssignment = $true
break
}
}
$properties = @("Group")
if($isFilterAssignment)
{
$properties += @("Filter","FilterMode")
}
}
Add-HTMLTableItems $obj $objectType $documentedObj.Assignments $properties "TableHeaders.assignments" -AddCategories
}
}
catch
{
Write-LogError "Failed to process object $objName" $_.Exception
}
if($script:outputType -eq "Object")
{
$script:htmlContent = [System.Text.StringBuilder]::new()
$script:htmlContent.AppendLine("<HTML>")
$script:htmlContent.AppendLine($script:cssStyle)
$htmlText = $script:htmlContent.ToString()
$htmlText += $script:htmlStrings.ToString()
$htmlText += "</HTML>"
$fileName = "$($script:documentPath)\$($script:currentItemFileName)"
Save-DocumentationFile $htmlText $fileName
$script:htmlStrings = $null
}
}
function Add-HTMLTableItems
{
param($obj, $objectType, $items, $properties, $lngId, [switch]$AddCategories, [switch]$AddSubcategories, $captionOverride)
if($captionOverride)
{
$caption = $captionOverride
}
elseif($lngId)
{
$caption = "$((Get-LanguageString $lngId)) - $((Get-GraphObjectName $obj $objectType))"
}
else
{
$caption = "$((Get-GraphObjectName $obj $objectType)) ($($objectType.Title))"
}
$tableText = [System.Text.StringBuilder]::new()
$tableText.AppendLine("<table class='table-settings'>")
# Add Header row
$tableText.AppendLine("<tr>")
$columnCount = 0
foreach($prop in $properties)
{
$tableText.AppendLine("<th>$((Invoke-DocTranslateColumnHeader $prop.Split(".")[-1]))</th>")
$columnCount++
}
$tableText.AppendLine("</tr>")
$curCategory = ""
$curSubCategory = ""
$columnCategory = $null
$columnSubCategory = $null
$row = 1
foreach($itemObj in $items)
{
$newCategory = $false
$newSubCategory = $false
$additionalRowClass = ""
if($itemObj.Category -and $curCategory -ne $itemObj.Category -and $AddCategories -eq $true)
{
# Add Category row
$tableText.AppendLine("<tr>")
$tableText.AppendLine("<td colspan=`"$($columnCount)`" class='category-level1'>$($itemObj.Category)</td>")
$tableText.AppendLine("</tr>")
$curCategory = $itemObj.Category
$curSubCategory = ""
$row = 1
$newCategory = $true
$curentPropertyIndex = 0
}
if($itemObj.SubCategory -and $curSubCategory -ne $itemObj.SubCategory -and $AddSubcategories -eq $true)
{
# Add Sub-category row
$tableText.AppendLine("<tr>")
$tableText.AppendLine("<td colspan=`"$($columnCount)`" class='category-level2'>$($itemObj.SubCategory)</td>")
$tableText.AppendLine("</tr>")
$curSubCategory = $itemObj.SubCategory
$row = 1
$newSubCategory = $true
$curentPropertyIndex = 0
}
if($itemObj.PropertyIndex -is [int] -and $itemObj.PropertyIndex -gt 0 -and $itemObj.PropertyIndex -eq 1)
{
$curentPropertyIndex = $itemObj.PropertyIndex
$additionalRowClass = "row-new-property"
}
try
{
if(($row % 2) -eq 1)
{
$rowClass = "row-odd"
}
else
{
$rowClass = "row-even"
}
$row++
$tableText.AppendLine("<tr class='$($rowClass) $($additionalRowClass)'>")
$curCol = 1
foreach($prop in $properties)
{
try
{
$propArr = $prop.Split('.')
$tmpObj = $itemObj
$propName = $propArr[-1]
for($x = 0; $x -lt ($propArr.Count - 1);$x++)
{
$tmpObj = $tmpObj."$($propArr[$x])"
}
if($propName -eq "Value" -and ($itemObj.FullValueTable | measure).Count -gt 0)
{
$tableText.AppendLine("<td><table class='table-value'>")
$tableText.AppendLine("<tr>")
foreach($tableObjectProp in $itemObj.FullValueTable[0].PSObject.Properties)
{
$tableText.AppendLine("<th>$($tableObjectProp.Name)</th>")
}
$tableText.AppendLine("</tr>")
foreach($tableValue in $itemObj.FullValueTable)
{
$tableText.AppendLine("<tr>")
foreach($tableObjectProp in $itemObj.FullValueTable[0].PSObject.Properties)
{
$tableText.AppendLine("<td>$($tableValue."$($tableObjectProp.Name)")</td>")
}
$tableText.AppendLine("</tr>")
}
$tableText.AppendLine("</table></td>")
}
else
{
$style = ""
if($curCol -eq 1 -and $itemObj.Level)
{
try
{
$level = [int]$itemObj.Level
$style = " style='padding-left:$((5 + ($level * 5)))px;'"
}
catch{}
}
$tableText.AppendLine("<td class='property-column$($curCol)'$style>$((Set-HTMLText $tmpObj.$propName))</td>")
}
}
catch
{
Write-LogError "Failed to add property value for $prop" $_.Exception
}
$curCol++
}
}
catch
{
Write-Log "Failed to process property" 2
}
finally
{
$tableText.AppendLine("</tr>")
}
}
$tableText.AppendLine("</table>")
$script:htmlStrings.Append($tableText.ToString())
Add-HTMLHeader $caption -level 6
}
function Invoke-HTMLProcessAllObjects
{
param($documentationInfo)
$scopeTagInfo = Get-TableObjects "ScopeTags"
if($allObjectTypeObjdocumentationInfoects.ObjectType.Id -eq "ScopeTags")
{
if(($documentationInfo.Items | measure).Count -gt 0)
{
Add-HTMLHeader $documentationInfo.TypeName
Add-HTMLTableItems $null $documentationInfo.ObjectType $documentationInfo.Items -captionOverride (Get-LanguageString "SettingDetails.scopeTags")
}
}
}
function Set-HTMLText
{
param([string]$text, [switch]$NoCodeBlock)
if(-not $text)
{
return
}
$txtSummary = ""
if($text -and $text.Length -gt 250)
{
$summaryMax = 40
# Show the first row or the first $max characters if first row is too short or too long
$idx = $text.IndexOfAny(@("`r","`n"))
if($idx -gt 10 -and $idx -lt 50)
{
$summaryMax = $idx
}
$txtSummary = $text.SubString(0,$summaryMax)
}
$code = $false
if($NoCodeBlock -ne $true)
{
$trimText = $text.Trim()
if($trimText.StartsWith("<") -and $trimText.EndsWith(">"))
{
$code = $true
$text = "<pre class='code'>$($text.Replace('&', '&amp;').Replace('<', '&lt;').Replace('>', '&gt;').Replace('"', '&quot;'))</pre>"
if($txtSummary)
{
$txtSummary = $txtSummary.Replace('&', '&amp;').Replace('<', '&lt;').Replace('>', '&gt;').Replace('"', '&quot;')
}
}
}
if($code -eq $false)
{
$text = $text.Replace("`r`n", "<br />")
$text = $text.Replace("`n", "<br />")
$text = $text.Replace('&', '&amp;')
}
if($txtSummary)
{
"<details class='description'><summary data-open='Minimize' data-close='$($txtSummary)...expand'></summary>$text</details>"
}
else
{
$text
}
}
function Add-HTMLObjectSettings
{
param($obj, $objectType, $documentedObj)
foreach($objectScript in $documentedObj.Scripts)
{
if(-not $objectScript.ScriptContent -or -not $objectScript.Caption) { continue }
$script:htmlStrings.AppendLine("<pre class='code'>")
$script:htmlStrings.AppendLine($objectScript.ScriptContent)
$script:htmlStrings.AppendLine("</pre>")
Add-HTMLHeader $objectScript.Caption -Level 6 -SkipTOC
}
}

View File

@@ -1,34 +1,127 @@
function Get-ModuleVersion
{
'1.0.0'
'1.1.0'
}
function Invoke-InitializeModule
{
Add-OutputType ([PSCustomObject]@{
Name="Markdown (Experimental)"
Name="Markdown"
Value="md"
#OutputOptions = (Add-MDOptionsControl)
OutputOptions = (Add-MDOptionsControl)
#Activate = { Invoke-MDActivate @args }
PreProcess = { Invoke-MDPreProcessItems @args }
NewObjectGroup = { Invoke-MDNewObjectGroup @args }
NewObjectGroup = { Invoke-MDNewObjectGroup2 @args }
NewObjectType = { Invoke-MDNewObjectType2 @args }
Process = { Invoke-MDProcessItem @args }
PostProcess = { Invoke-MDPostProcessItems @args }
ProcessAllObjects = { Invoke-MDProcessAllObjects @args }
})
}
function Add-MDOptionsControl
{
$script:mdForm = Get-XamlObject ($global:AppRootFolder + "\Xaml\DocumentationMDOptions.xaml") -AddVariables
Set-XamlProperty $script:mdForm "txtMDDocumentName" "Text" (Get-Setting "Documentation" "MDDocumentName" "")
Set-XamlProperty $script:mdForm "txtMDCSSFile" "Text" (Get-Setting "Documentation" "MDCSSFile" "")
Set-XamlProperty $script:mdForm "chkMDIncludeCSS" "IsChecked" (Get-Setting "Documentation" "MDIncludeCSS" $true)
Set-XamlProperty $script:mdForm "chkMDOpenDocument" "IsChecked" (Get-Setting "Documentation" "MDOpenFile" $true)
Set-XamlProperty $script:mdForm "cbMDDocumentOutputFile" "ItemsSource" ("[ { Name: `"Single file`",Value: `"Full`" }, { Name: `"One file per object`",Value: `"Object`" }]" | ConvertFrom-Json)
Set-XamlProperty $script:mdForm "cbMDDocumentOutputFile" "SelectedValue" (Get-Setting "Documentation" "MDDocumentFileType" "Full")
Add-XamlEvent $script:mdForm "browseMDDocumentName" "add_click" {
$sf = [System.Windows.Forms.SaveFileDialog]::new()
$sf.DefaultExt = "*.md"
$sf.Filter = "MD (*.md)|*.md|All files (*.*)|*.*"
if($sf.ShowDialog() -eq "OK")
{
Set-XamlProperty $script:MDForm "txtMDDocumentName" "Text" $sf.FileName
Save-Setting "Documentation" "MDDocumentName" $sf.FileName
}
}
Add-XamlEvent $script:mdForm "browseMDCSSFile" "add_click" {
$of = [System.Windows.Forms.OpenFileDialog]::new()
$of.Multiselect = $false
$of.Filter = "CSS Files (*.css)|*.css|All files (*.*)|*.*"
if($of.ShowDialog())
{
Set-XamlProperty $script:mdForm "txtMDCSSFile" "Text" $of.FileName
Save-Setting "Documentation" "txtMDCSSFile" $of.FileName
}
}
$script:mdForm
}
function Invoke-MDProcessAllObjects
{
param($allObjectTypeObjects, $objectType)
}
function Invoke-MDPreProcessItems
{
$script:mdStrings = [System.Text.StringBuilder]::new()
$script:sectionAnchors = @()
$script:totAnchors = @()
$script:mdStrings = $null
$script:currentItemFileName = $null
Save-Setting "Documentation" "MDDocumentName" (Get-XamlProperty $script:mdForm "txtMDDocumentName" "Text" "")
Save-Setting "Documentation" "MDIncludeCSS" (Get-XamlProperty $script:mdForm "chkMDIncludeCSS" "IsChecked")
Save-Setting "Documentation" "MDCSSFile" (Get-XamlProperty $script:mdForm "txtMDCSSFile" "Text" "")
Save-Setting "Documentation" "MDOpenFile" (Get-XamlProperty $script:mdForm "chkMDOpenDocument" "IsChecked")
Save-Setting "Documentation" "MDDocumentFileType" (Get-XamlProperty $script:mdForm "cbMDDocumentOutputFile" "SelectedValue" '')
$defaultCSSFile = $global:AppRootFolder + "\Documentation\DefaultMDStyle.css"
$MDCssFile = Get-XamlProperty $script:mdForm "txtMDCSSFile" "Text" $defaultCSSFile
if(-not $MDCssFile)
{
Write-Log "CSS file not specified. Using default" 2
$MDCssFile = $defaultCSSFile
}
elseif([IO.File]::Exists($MDCssFile) -eq -$false)
{
Write-Log "CSS file $($MDCssFile) not found. Using default" 2
$MDCssFile = $defaultCSSFile
}
$cssStyle = ""
if([IO.File]::Exists($MDCssFile))
{
Write-Log "Using CSS file $($MDCssFile)"
$cssStyle = Get-Content -Raw -Path $MDCssFile
$cssStyle += [System.Environment]::NewLine
}
else
{
Write-Log "CSS file $($MDCssFile) not found. No styles applied" 2
}
$script:cssStyle = $cssStyle
$fileName = Expand-FileName (Get-XamlProperty $script:mdForm "txtMDDocumentName" "Text" "%MyDocuments%\%Organization%-%Date%.md")
$script:outFile = $fileName
$script:documentPath = [io.path]::GetDirectoryName($fileName)
$script:outputType = (Get-XamlProperty $script:mdForm "cbMDDocumentOutputFile" "SelectedValue" "Full")
if($script:outputType -eq "Object")
{
Write-Log "Document one file for each object + index file"
}
else
{
Write-Log "Document one single file for all objects"
$script:outputType = "Full"
$script:mdStrings = [System.Text.StringBuilder]::new()
}
}
function Invoke-MDPostProcessItems
{
$userName = $global:me.displayName
if($global:me.givenName -and $global:me.surname)
{
@@ -59,24 +152,38 @@ function Invoke-MDPostProcessItems
foreach($header in $script:sectionAnchors)
{
$script:mdContent.AppendLine("[$($header.Name)](#$($header.Anchor))`n")
$indent = [String]::new(" ", (($header.Level - 1) * 2))
$script:mdContent.AppendLine("$($indent)- [$($header.Name)]($($header.FileName)#$($header.Anchor))`n")
}
$mdText = $script:cssStyle
$script:mdContent.AppendLine("")
$mdText = $script:mdContent.ToString()
$mdText += $script:mdStrings.ToString()
$mdText += $script:mdContent.ToString()
if($script:outputType -eq "Full")
{
$mdText += $script:mdStrings.ToString()
}
$fileName = Expand-FileName "%MyDocuments%\%Organization%-%Date%.md"
Save-DocumentationFile $mdText $script:outFile -OpenFile:((Get-Setting "Documentation" "MDOpenFile" $true) -eq $true)
<#
$fileName = Expand-FileName (Get-XamlProperty $script:mdForm "txtMDDocumentName" "Text" "%MyDocuments%\%Organization%-%Date%.md")
try
{
$mdText | Out-File -FilePath $fileName -Force -Encoding utf8 -ErrorAction Stop
Write-Log "Markdown document $fileName saved successfully"
if((Get-Setting "Documentation" "MDOpenFile" $true) -eq $true)
{
Invoke-Item $fileName
}
}
catch
{
Write-LogError "Failed to save Markdown file" $_.Exception
Write-LogError "Failed to save Markdown file: $fileName." $_.Exception
}
#>
}
function Invoke-MDNewObjectGroup
@@ -86,7 +193,39 @@ function Invoke-MDNewObjectGroup
$objectTypeString = Get-ObjectTypeString $obj.Object $obj.ObjectType
Add-MDHeader "$((?? $objectTypeString $obj.ObjectType.Title))" -Level 1 -USEHtml
}
function Invoke-MDNewObjectType
{
param($obj, $documentedObj, [int]$groupCategoryCount = 0)
if($obj.ObjectType.GroupId -eq "EndpointSecurity")
{
$objectTypeString = $obj.CategoryName
}
else
{
$objectTypeString = $obj.ObjectType.Title
}
Add-MDHeader "$((?? $objectTypeString $obj.ObjectType.Title))" -Level 2 -USEHtml
}
function Invoke-MDNewObjectGroup2
{
param($groupId)
$objectTypeString = Get-ObjectTypeString -ObjectType $groupId
Add-MDHeader $objectTypeString -Level 1 -USEHtml
}
function Invoke-MDNewObjectType2
{
param($objectTypeName)
Add-MDHeader $objectTypeName -Level 2 -USEHtml
}
function Invoke-MDProcessItem
@@ -97,7 +236,14 @@ function Invoke-MDProcessItem
$objName = Get-GraphObjectName $obj $objectType
Add-MDHeader $objName -Level 2 -USEHtml
if($script:outputType -eq "Object")
{
$script:totAnchors = @()
$script:mdStrings = [System.Text.StringBuilder]::new()
$script:currentItemFileName = "./$((Remove-InvalidFileNameChars "$($objName).md").Replace(" ","_"))"
}
Add-MDHeader $objName -Level 3 -USEHtml
$script:mdStrings.AppendLine("")
@@ -164,7 +310,6 @@ function Invoke-MDProcessItem
if(($documentedObj.Assignments | measure).Count -gt 0)
{
$params = @{}
if($documentedObj.Assignments[0].RawIntent)
{
$properties = @("GroupMode","Group","Filter","FilterMode")
@@ -197,15 +342,26 @@ function Invoke-MDProcessItem
{
$properties += @("Filter","FilterMode")
}
$params.Add("AddCategories", $true)
}
Add-MDTableItems $obj $objectType $documentedObj.Assignments $properties "TableHeaders.assignments" @params
Add-MDTableItems $obj $objectType $documentedObj.Assignments $properties "TableHeaders.assignments" -AddCategories
}
}
catch
{
Write-LogError "Failed to process object $objName" $_.Exception
}
if($script:outputType -eq "Object")
{
$script:mdContent = [System.Text.StringBuilder]::new()
$script:mdContent.AppendLine($script:cssStyle)
$mdText = $script:mdContent.ToString()
$mdText += $script:mdStrings.ToString()
$fileName = "$($script:documentPath)\$($script:currentItemFileName)"
Save-DocumentationFile $mdText $fileName
$script:mdStrings = $null
}
}
@@ -227,24 +383,17 @@ function Add-MDTableItems
}
$tableText = [System.Text.StringBuilder]::new()
$tableText.AppendLine("<table>")
$tableText.AppendLine("<tr>")
$columnHeaders = "|"
$columnChars = "|"
$tableText.AppendLine("<table class='table-settings'>")
$tableText.AppendLine("<tr class='table-header1'>")
$columnCount = 0
foreach($prop in $properties)
{
$tableText.AppendLine("<td> $($prop.Split(".")[-1]) </td>")
$tableText.AppendLine("<td>$((Invoke-DocTranslateColumnHeader $prop.Split(".")[-1]))</td>")
$columnCount++
$columnHeaders += ((Invoke-DocTranslateColumnHeader ($prop.Split(".")[-1])) + "|")
$columnChars += "----|"
}
$tableText.AppendLine("</tr>")
#Add-MDText $columnHeaders
#Add-MDText $columnChars
$curCategory = ""
$curSubCategory = ""
@@ -253,34 +402,39 @@ function Add-MDTableItems
foreach($itemObj in $items)
{
$additionalRowClass = ""
if($itemObj.Category -and $curCategory -ne $itemObj.Category -and $AddCategories -eq $true)
{
$tableText.AppendLine("<tr>")
$tableText.AppendLine("<td colspan=`"$($columnCount)`">`n`n**$((Set-MDText $itemObj.Category))**`n`n</td>")
$tableText.AppendLine("<td colspan=`"$($columnCount)`" class='category-level1'>$((Set-MDText $itemObj.Category))</td>")
$tableText.AppendLine("</tr>")
#$columnCategory = "|**" + (Set-MDText $itemObj.Category) + "**|"
#Add-MDText $columnCategory
$curCategory = $itemObj.Category
$curSubCategory = ""
$curentPropertyIndex = 0
}
if($itemObj.SubCategory -and $curSubCategory -ne $itemObj.SubCategory -and $AddSubcategories -eq $true)
{
$tableText.AppendLine("<tr>")
$tableText.AppendLine("<td colspan=`"$($columnCount)`">`n`n***$((Set-MDText $itemObj.SubCategory))***`n`n</td>")
$tableText.AppendLine("<td colspan=`"$($columnCount)`" class='category-level2'>$((Set-MDText $itemObj.SubCategory))</td>")
$tableText.AppendLine("</tr>")
#$columnSubCategory = "|***" + (Set-MDText $itemObj.SubCategory) + "***|"
#Add-MDText $columnSubCategory
$curSubCategory = $itemObj.SubCategory
$curentPropertyIndex = 0
}
if($itemObj.PropertyIndex -is [int] -and $itemObj.PropertyIndex -gt 0 -and $itemObj.PropertyIndex -eq 1)
{
$curentPropertyIndex = $itemObj.PropertyIndex
$additionalRowClass = "row-new-property"
}
#$columnData = "|"
try
{
$tableText.AppendLine("<tr>")
$tableText.AppendLine("<tr class='$($additionalRowClass)'>")
$curCol = 1
foreach($prop in $properties)
{
try
@@ -293,7 +447,49 @@ function Add-MDTableItems
{
$tmpObj = $tmpObj."$($propArr[$x])"
}
$tableText.AppendLine("<td>$((Set-MDText "$($tmpObj.$propName)" -CodeBlock))</td>")
if($propName -eq "Value" -and ($itemObj.FullValueTable | measure).Count -gt 0)
{
$tableText.AppendLine("<td><table class='table-value'>")
$tableText.AppendLine("<tr>")
foreach($tableObjectProp in $itemObj.FullValueTable[0].PSObject.Properties)
{
$tableText.AppendLine("<td class='table-header1'>$($tableObjectProp.Name)</td>")
}
$tableText.AppendLine("</tr>")
foreach($tableValue in $itemObj.FullValueTable)
{
$tableText.AppendLine("<tr>")
foreach($tableObjectProp in $itemObj.FullValueTable[0].PSObject.Properties)
{
$tableText.AppendLine("<td>$($tableValue."$($tableObjectProp.Name)")</td>")
}
$tableText.AppendLine("</tr>")
}
$tableText.AppendLine("</table></td>")
}
else
{
$style = ""
if($curCol -eq 1 -and $itemObj.Level)
{
try
{
$level = [int]$itemObj.Level
$style = " style='padding-left:$((5 + ($level * 5)))px !important;'"
}
catch{}
}
$params = @{}
if($curCol -gt 0)
{
$params.Add("CodeBlock", $true)
}
$tableText.AppendLine("<td class='property-column$($curCol)'$style>$((Set-MDText $tmpObj.$propName @params))</td>")
}
#$columnData += "$((Set-MDText "$($tmpObj.$propName)"))|"
}
catch
@@ -301,6 +497,7 @@ function Add-MDTableItems
#$columnData += "|"
Write-LogError "Failed to add property value for $prop" $_.Exception
}
$curCol++
}
}
@@ -337,57 +534,93 @@ function Add-MDText
function Set-MDText
{
param($text, [switch]$CodeBlock)
param([string]$text, [switch]$CodeBlock)
if($null -eq $text) { return }
$txtSummary = ""
$textOut = ""
if($text -and $text.Length -gt 250)
{
$summaryMax = 40
# Show the first row or the first $max characters if first row is too short or too long
$idx = $text.IndexOfAny(@("`r","`n"))
if($idx -gt 10 -and $idx -lt 50)
{
$summaryMax = $idx
}
$txtSummary = $text.SubString(0,$summaryMax)
}
if($CodeBlock -eq $true)
{
$trimText = $text.Trim()
if($trimText.StartsWith("<") -and $trimText.EndsWith(">"))
if($trimText.StartsWith("<?xml") -or $trimText.StartsWith("<xml") -or ($trimText.StartsWith("<") -and $trimText.EndsWith(">")))
{
return ([Environment]::NewLine + [Environment]::NewLine + "``````xml" + [Environment]::NewLine + $text + [Environment]::NewLine + "``````" + [Environment]::NewLine + [Environment]::NewLine)
$textOut = ([Environment]::NewLine + [Environment]::NewLine + "``````xml" + [Environment]::NewLine + $text + [Environment]::NewLine + "``````" + [Environment]::NewLine + [Environment]::NewLine)
}
}
if($CodeBlock -eq $false -or -not $textOut)
{
$text = $text.Replace("|", '`|')
$text = $text.Replace("*", '`*')
$text = $text.Replace("$", '`$')
$text = $text.Replace("`r`n", "<br />")
$textOut = $text.Replace("`n", "<br />")
}
$text = $text.Replace("|", '`|')
$text = $text.Replace("*", '`*')
$text = $text.Replace("$", '`$')
$text = $text.Replace("`r`n", "<br />")
$text = $text.Replace("`n", "<br />")
$text
if($txtSummary)
{
"<details class='description'><summary data-open='Minimize' data-close='$($txtSummary)...expand'></summary>$textOut</details>"
}
else
{
$textOut
}
}
function Add-MDHeader
{
param($text, [int]$level = 1, [switch]$AddParagraph, [switch]$UseHTML, [switch]$ToT, [switch]$SkipTOC)
$prefix = ""
if($ToT -eq $true)
{
$prefix = "Table $(($script:totAnchors.Count + 1)). "
}
if($UseHTML -eq $true)
if($script:mdStrings)
{
$prefix = ""
if($ToT -eq $true)
{
$sectionAnchor = "table-$(($script:totAnchors.Count + 1))"
}
else
{
$sectionAnchor = "section-$(($script:sectionAnchors.Count + 1))"
}
$script:mdStrings.AppendLine("<h$level id=`"$prefix$($sectionAnchor)`">$text</h$level>")
}
else
{
# Warnig: Not complete! Use HTML if not working...
$text = "$prefix$text"
$sectionAnchor = $text.ToLower().Replace(" ","-").Replace("[","").Replace("]","")
$prefix = "Table $(($script:totAnchors.Count + 1)). "
}
$mdHeader = [String]::new('#',$level)
$script:mdStrings.AppendLine("$mdHeader $text")
if($UseHTML -eq $true)
{
if($ToT -eq $true)
{
$sectionAnchor = "table-$(($script:totAnchors.Count + 1))"
}
else
{
$sectionAnchor = "section-$(($script:sectionAnchors.Count + 1))"
}
$script:mdStrings.AppendLine("<h$level id=`"$prefix$($sectionAnchor)`">$text</h$level>")
}
else
{
# Warnig: Not complete! Use HTML if not working...
$text = "$prefix$text"
$sectionAnchor = $text.ToLower().Replace(" ","-").Replace("[","").Replace("]","")
$mdHeader = [String]::new('#',$level)
$script:mdStrings.AppendLine("$mdHeader $text")
}
$FileName = $script:currentItemFileName
}
else
{
$sectionAnchor = $null
$FileName = $null
}
if($ToT -eq $true)
@@ -395,6 +628,8 @@ function Add-MDHeader
$script:totAnchors += [PSCustomObject]@{
Name = $text
Anchor = $sectionAnchor
FileName = $FileName
Level = $level
}
}
elseif($SkipTOC -ne $true)
@@ -402,6 +637,8 @@ function Add-MDHeader
$script:sectionAnchors += [PSCustomObject]@{
Name = $text
Anchor = $sectionAnchor
FileName = $FileName
Level = $level
}
}
@@ -415,68 +652,14 @@ function Add-MDHeader
function Add-MDObjectSettings
{
param($obj, $objectType, $documentedObj)
if($obj."@OData.Type" -eq "#microsoft.graph.deviceManagementScript")
foreach($objectScript in $documentedObj.Scripts)
{
if($obj.ScriptContent)
{
$script:mdStrings.AppendLine("~~~powershell")
$script:mdStrings.AppendLine((Get-DocScriptContent $obj.ScriptContent))
$script:mdStrings.AppendLine("~~~")
$caption = "{1} - {0}" -f $obj.fileName,(Get-LanguageString "WindowsManagement.powerShellScriptObjectName")
Add-MDHeader $caption -Level 6 -SkipTOC -AddParagraph
}
}
if($obj."@OData.Type" -eq "#microsoft.graph.deviceShellScript")
{
if($obj.ScriptContent)
{
$script:mdStrings.AppendLine("~~~shell")
$script:mdStrings.AppendLine((Get-DocScriptContent $obj.ScriptContent))
$script:mdStrings.AppendLine("~~~")
if(-not $objectScript.ScriptContent -or -not $objectScript.Caption) { continue }
$caption = "{1} - {0}" -f $obj.fileName,(Get-LanguageString "WindowsManagement.shellScriptObjectName")
Add-MDHeader $caption -Level 6 -SkipTOC -AddParagraph
}
}
elseif($obj."@OData.Type" -eq "#microsoft.graph.deviceHealthScript")
{
if($obj.detectionScriptContent)
{
$script:mdStrings.AppendLine("~~~powershell")
$script:mdStrings.AppendLine((Get-DocScriptContent $obj.detectionScriptContent))
$script:mdStrings.AppendLine("~~~")
$caption = Get-LanguageString "ProactiveRemediations.Create.Settings.DetectionScriptMultiLineTextBox.label"
Add-MDHeader $caption -Level 6 -SkipTOC -AddParagraph
}
if($obj.remediationScriptContent)
{
$script:mdStrings.AppendLine("~~~powershell")
$script:mdStrings.AppendLine((Get-DocScriptContent $obj.remediationScriptContent))
$script:mdStrings.AppendLine("~~~")
$caption = Get-LanguageString "ProactiveRemediations.Create.Settings.RemediationScriptMultiLineTextBox.label"
Add-MDHeader $caption -Level 6 -SkipTOC -AddParagraph
}
}
elseif($obj."@OData.Type" -eq "#microsoft.graph.win32LobApp")
{
foreach($rule in ($obj.requirementRules | Where { $_.'@OData.Type' -eq "#microsoft.graph.win32LobAppPowerShellScriptRequirement" } ))
{
$script:mdStrings.AppendLine("~~~powershell")
$script:mdStrings.AppendLine((Get-DocScriptContent $obj.scriptContent))
$script:mdStrings.AppendLine("~~~")
$caption = "{0} - {1}" -f @($obj.displayName, "Requirement script")
Add-MDHeader $caption -Level 6 -SkipTOC -AddParagraph
}
foreach($rule in ($obj.detectionRules | Where { $_.'@OData.Type' -eq "#microsoft.graph.win32LobAppPowerShellScriptDetection" } ))
{
$script:mdStrings.AppendLine("~~~powershell")
$script:mdStrings.AppendLine((Get-DocScriptContent $obj.scriptContent))
$script:mdStrings.AppendLine("~~~")
$caption = "{0} - {1}" -f @($obj.displayName,(Get-LanguageString "ProactiveRemediations.Create.Settings.DetectionScriptMultiLineTextBox.label"))
Add-MDHeader $caption -Level 6 -SkipTOC -AddParagraph
}
$script:mdStrings.AppendLine("~~~powershell")
$script:mdStrings.AppendLine($objectScript.ScriptContent)
$script:mdStrings.AppendLine("~~~")
Add-MDHeader $objectScript.Caption -Level 6 -SkipTOC -AddParagraph
}
}

View File

@@ -3,7 +3,7 @@
#https://docs.microsoft.com/en-us/office/vba/api/overview/word
function Get-ModuleVersion
{
'1.4.0'
'1.5.0'
}
function Invoke-InitializeModule
@@ -76,8 +76,6 @@ function Add-WordOptionsControl
$global:txtWordTitleProperty.Text = Get-Setting "Documentation" "WordTitleProperty" "Intune documentation"
$global:txtWordSubjectProperty.Text = Get-Setting "Documentation" "WordSubjectProperty" "Intune documentation"
$global:chkWordIncludeScripts.IsChecked = ((Get-Setting "Documentation" "WordIncludeScripts" "true") -ne "false")
$global:chkWordExcludeScriptSignature.IsChecked = ((Get-Setting "Documentation" "WordExcludeScriptSignature" "false") -ne "false")
$global:chkWordAttachJsonFile.IsChecked = ((Get-Setting "Documentation" "WordAttatchJsonFile" "false") -ne "false")
$global:txtWordScriptTableStyle.Text = Get-Setting "Documentation" "WordScriptTableStyle" ""
@@ -142,8 +140,6 @@ function Invoke-WordPreProcessItems
Save-Setting "Documentation" "WordTitleProperty" $global:txtWordTitleProperty.Text
Save-Setting "Documentation" "WordSubjectProperty" $global:txtWordSubjectProperty.Text
Save-Setting "Documentation" "WordIncludeScripts" $global:chkWordIncludeScripts.IsChecked
Save-Setting "Documentation" "WordExcludeScriptSignature" $global:chkWordExcludeScriptSignature.IsChecked
Save-Setting "Documentation" "WordAttatchJsonFile" $global:chkWordAttachJsonFile.IsChecked
Save-Setting "Documentation" "WordScriptTableStyle" $global:txtWordScriptTableStyle.Text
@@ -466,35 +462,22 @@ function Set-WordContentControlText
function Invoke-WordNewObjectGroup
{
param($obj, $documentedObj)
param($groupId)
$script:objectHeaderLevel = 2
$objectTypeString = Get-ObjectTypeString -ObjectType $groupId
$objectTypeString = Get-ObjectTypeString $obj.Object $obj.ObjectType
Add-DocText (?? $objectTypeString $obj.ObjectType.Title) $global:txtWordHeader1Style.Text
Add-DocText $objectTypeString $global:txtWordHeader1Style.Text
}
function Invoke-WordNewObjectType
{
param($obj, $documentedObj, [int]$groupCategoryCount = 0)
param($objectTypeName)
if($groupCategoryCount -le 1 -or -not $global:txtWordHeader3Style.Text) { return }
$script:objectHeaderLevel = 2
if($obj.ObjectType.GroupId -eq "EndpointSecurity")
{
$objectTypeString = $obj.CategoryName
}
else
{
$objectTypeString = $obj.ObjectType.Title
}
Add-DocText $objectTypeName (Get-ObjectLevelHeader)
Add-DocText (?? $objectTypeString $obj.ObjectType.Title) (Get-ObjectLevelHeader)
$script:objectHeaderLevel = 3;
$script:objectHeaderLevel = 3
}
function local:Get-ObjectLevelHeader
@@ -698,7 +681,6 @@ function Set-DocTableSettingsItems
$tmpObj = $tmpObj."$($propArr[$x])"
}
#$script:docTable.Cell($cellRow, $secondColumn).Column.Cells($cellRow).Range.Text = "$($tmpObj.$propName)"
$script:docTable.Cell($cellRow, $secondColumn).Range.Text = "$($tmpObj.$propName)"
$cellRow++
@@ -735,6 +717,7 @@ function Invoke-WordProcessAllObjects
$nameLabel = $obj.displayName
ID = $obj.Id
$descriptionLable = $obj.Description
Object = $obj
}
}
@@ -803,10 +786,23 @@ function Add-DocTableItems
$curSubCategory = ""
$row = 2
$curentPropertyIndex = 0
foreach($itemObj in $items)
{
try
{
if(($itemObj.Category -and $curCategory -ne $itemObj.Category -and $AddCategories -eq $true) -or
($itemObj.SubCategory -and $curSubCategory -ne $itemObj.SubCategory -and $AddSubcategories -eq $true))
{
$curentPropertyIndex = 0
}
if($itemObj.PropertyIndex -is [int] -and $itemObj.PropertyIndex -gt 0 -and $itemObj.PropertyIndex -eq 1)
{
$curentPropertyIndex = $itemObj.PropertyIndex
# !!! ToDo: Set style for new property
}
$i = 1
foreach($prop in $properties)
{
@@ -840,9 +836,24 @@ function Add-DocTableItems
}
}
$levelExtra = ""
if($i -eq 1 -and $itemObj.Level)
{
try
{
$level = ([int]$itemObj.Level) # - 1
if($level -lt 0) { $level = 0 }
if($level -gt 0)
{
$levelExtra = [String]::new(" ", ($level * 2)) #Should probably use tab stops instead
}
}
catch{}
}
if($null -ne $propValue)
{
$script:docTable.Cell($row, $i).Range.Text = $propValue
$script:docTable.Cell($row, $i).Range.Text = "$levelExtra$propValue"
}
if($propValueFull -and $global:chkWordDocumentationLimitAttach.IsChecked -eq $true)
@@ -859,7 +870,6 @@ function Add-DocTableItems
$propValueFull | Out-File -LiteralPath $tmpFile -Force
$fi = [IO.FileInfo]$tmpFile
[void]$script:docTable.Cell($row, $i).Range.InlineShapes.AddOLEObject("",$fi.FullName,$false,$true,"$($env:WinDir)\System32\Notepad.exe",0,"Full value")
#$script:doc.Application.Selection.InlineShapes.AddOLEObject("",$fi.FullName,$false,$true,"$($env:WinDir)\System32\Notepad.exe",0,"Full value", $script:docTable.Cell($row, $i).Range)
try { $fi.Delete() } catch {}
}
}
@@ -1050,85 +1060,14 @@ function Set-DocObjectStyle
$styleSet
}
function Add-DocObjectSettings
function Add-DocObjectSettings
{
param($obj, $objectType, $documentedObj)
if($obj."@OData.Type" -eq "#microsoft.graph.deviceManagementScript")
foreach($objectScript in $documentedObj.Scripts)
{
if($obj.ScriptContent -and $global:chkWordIncludeScripts.IsChecked -eq $true)
{
$caption = "{1} - {0}" -f $obj.displayName,(Get-LanguageString "WindowsManagement.powerShellScriptObjectName")
Add-DocTableScript $caption $obj.FileName (Get-DocScriptContent $obj.ScriptContent)
}
}
if($obj."@OData.Type" -eq "#microsoft.graph.deviceShellScript")
{
if($obj.ScriptContent -and $global:chkWordIncludeScripts.IsChecked -eq $true)
{
$caption = "{1} - {0}" -f $obj.displayName,(Get-LanguageString "WindowsManagement.shellScriptObjectName")
Add-DocTableScript $caption $obj.FileName (Get-DocScriptContent $obj.ScriptContent)
}
}
elseif($obj."@OData.Type" -eq "#microsoft.graph.deviceHealthScript")
{
if($obj.detectionScriptContent)
{
$caption = Get-LanguageString "ProactiveRemediations.Create.Settings.DetectionScriptMultiLineTextBox.label"
$header = "{1} - {0}" -f $obj.displayName,$caption
Add-DocTableScript $header $caption (Get-DocScriptContent $obj.detectionScriptContent)
}
if(-not $objectScript.ScriptContent -or -not $objectScript.Caption) { continue }
if($obj.remediationScriptContent)
{
$caption = Get-LanguageString "ProactiveRemediations.Create.Settings.RemediationScriptMultiLineTextBox.label"
$header = "{1} - {0}" -f $obj.displayName,$caption
Add-DocTableScript $header $caption (Get-DocScriptContent $obj.remediationScriptContent)
}
}
elseif($obj."@OData.Type" -eq "#microsoft.graph.win32LobApp")
{
foreach($rule in ($obj.requirementRules | Where { $_.'@OData.Type' -eq "#microsoft.graph.win32LobAppPowerShellScriptRequirement" } ))
{
$caption = "{0} - {1}" -f @($obj.displayName, "Requirement script")
Add-DocTableScript $caption $rule.displayName (Get-DocScriptContent $rule.scriptContent)
}
foreach($rule in ($obj.detectionRules | Where { $_.'@OData.Type' -eq "#microsoft.graph.win32LobAppPowerShellScriptDetection" } ))
{
$caption = "{0} - {1}" -f @($obj.displayName,(Get-LanguageString "ProactiveRemediations.Create.Settings.DetectionScriptMultiLineTextBox.label"))
Add-DocTableScript $caption (Get-LanguageString "ProactiveRemediations.Create.Settings.DetectionScriptMultiLineTextBox.label") (Get-DocScriptContent $rule.scriptContent)
}
}
}
function Get-DocScriptContent
{
param($encodeContent)
if(-not $encodeContent) { return }
try
{
$scriptContent = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($encodeContent))
if($global:chkWordExcludeScriptSignature.IsChecked -eq $true)
{
$x = $scriptContent.IndexOf("# SIG # Begin signature block")
if($x -gt 0)
{
$scriptContent = $scriptContent.SubString(0,$x)
$scriptContent = $scriptContent + "# SIG # Begin signature block`nSignature data excluded..."
}
}
$scriptContent
}
catch
{
}
Add-DocTableScript $objectScript.Caption $objectScript.Header $objectScript.ScriptContent
}
}

View File

@@ -1,5 +1,4 @@
<#
<#
.SYNOPSIS
Module for managing Intune objects
@@ -11,7 +10,7 @@ This module is for the Endpoint Manager/Intune View. It manages Export/Import/Co
#>
function Get-ModuleVersion
{
'3.7.4'
'3.8.1'
}
function Invoke-InitializeModule
@@ -121,7 +120,7 @@ function Invoke-InitializeModule
ViewID = "IntuneGraphAPI"
API = "/identity/conditionalAccess/policies"
Permissons=@("Policy.Read.All","Policy.ReadWrite.ConditionalAccess","Application.Read.All")
Dependencies = @("NamedLocations","Applications","TermsOfUse")
Dependencies = @("NamedLocations","Applications","TermsOfUse","AuthenticationStrengths")
GroupId = "ConditionalAccess"
ImportExtension = { Add-ConditionalAccessImportExtensions @args }
PreImportCommand = { Start-PreImportConditionalAccess @args }
@@ -172,7 +171,8 @@ function Invoke-InitializeModule
PostCopyCommand = { Start-PostCopyEndpointSecurity @args }
PreUpdateCommand = { Start-PreUpdateEndpointSecurity @args }
Permissons=@("DeviceManagementConfiguration.ReadWrite.All")
GroupId = "EndpointSecurity"
Dependencies = @("ReusableSettings")
GroupId = "EndpointSecurity"
})
Add-ViewItem (New-Object PSObject -Property @{
@@ -454,6 +454,9 @@ function Invoke-InitializeModule
DetailExtension = { Add-DetailExtensionApplications @args }
PreImportAssignmentsCommand = { Start-PreImportAssignmentsApplications @args }
PreDeleteCommand = { Start-PreDeleteApplications @args }
PostExportCommand = { Start-PostExportApplications @args }
PostListCommand = { Start-PostListApplications @args }
ExportExtension = { Add-ScriptExportExtensions @args }
GroupId = "Apps"
ScopeTagsReturnedInList = $false
})
@@ -557,6 +560,8 @@ function Invoke-InitializeModule
Icon="DeviceConfiguration"
PostExportCommand = { Start-PostExportSettingsCatalog @args }
PreUpdateCommand = { Start-PreUpdateSettingsCatalog @args }
PostGetCommand = { Start-PostGetSettingsCatalog @args }
Dependencies = @("ReusableSettings")
GroupId = "DeviceConfiguration"
})
@@ -586,6 +591,7 @@ function Invoke-InitializeModule
QUERYLIST = "`$filter=isBuiltIn%20eq%20false"
Permissons=@("DeviceManagementRBAC.ReadWrite.All")
PostExportCommand = { Start-PostExportScopeTags @args }
PostGetCommand = { Start-PostGetScopeTags @args }
ImportOrder = 10
DocumentAll = $true
GroupId = "TenantAdmin"
@@ -658,6 +664,8 @@ function Invoke-InitializeModule
PreDeleteCommand = { Start-PreDeleteDeviceHealthScripts @args }
PreImportCommand = { Start-PreImportDeviceHealthScripts @args }
PreUpdateCommand = { Start-PreUpdateDeviceHealthScripts @args }
PostExportCommand = { Start-PostExportDeviceHealthScripts @args }
ExportExtension = { Add-ScriptExportExtensions @args }
Permissons=@("DeviceManagementConfiguration.ReadWrite.All")
GroupId = "EndpointAnalytics"
Icon = "Report"
@@ -696,6 +704,35 @@ function Invoke-InitializeModule
ViewProperties = @("fileName","status","Id")
})
#>
Add-ViewItem (New-Object PSObject -Property @{
Title = "Reusable Settings"
Id = "ReusableSettings"
ViewID = "IntuneGraphAPI"
API = "/deviceManagement/reusablePolicySettings"
PropertiesToRemove = @('Settings','@OData.Type')
PostGetCommand = { Start-PostGetReusableSettings @args }
ImportOrder = 70
Permissons=@("DeviceManagementConfiguration.ReadWrite.All")
ExpandAssignmentsList = $false
SkipRemoveProperties = @("@OData.Type")
Icon = "EndpointSecurity"
GroupId = "EndpointSecurity"
})
Add-ViewItem (New-Object PSObject -Property @{
Title = "Authentication Strengths"
Id = "AuthenticationStrengths"
ViewID = "IntuneGraphAPI"
API = "/identity/conditionalAccess/authenticationStrengths/policies"
PreImportCommand = { Start-PreImportCommandAuthenticationStrengths @args }
PropertiesToRemove = @()
ImportOrder = 45
Permissons=@("Policy.ReadWrite.ConditionalAccess")
ExpandAssignmentsList = $false
Icon = "ConditionalAccess"
GroupId = "EndpointSecurity"
})
}
function Invoke-EMAuthenticateToMSAL
@@ -1951,7 +1988,6 @@ function Start-PreImportCommandApplication
@{ "Import" = $false }
}
Write-Log "### TEST ### OData.Type: $($obj.'@OData.Type')"
if($obj.'@OData.Type' -eq '#microsoft.graph.officeSuiteApp')
{
if($obj.officeSuiteAppDefaultFileFormat -eq "notConfigured")
@@ -2034,6 +2070,70 @@ function Start-PreDeleteApplications
@{ "Delete" = $false }
}
}
function Start-PostExportApplications
{
param($obj, $objectType, $path)
if($global:chkExportScript.IsChecked)
{
$fileName = Get-GraphObjectFile $obj $objectType
$fi = [IO.FileInfo]"$path\$fileName"
try
{
foreach($rule in ($obj.detectionRules | Where '@OData.Type' -eq "#microsoft.graph.win32LobAppPowerShellScriptDetection"))
{
if($rule.ScriptContent)
{
[IO.File]::WriteAllBytes(("$path\$($fi.BaseName)_DetectionScript.ps1"), ([System.Convert]::FromBase64String($rule.ScriptContent)))
}
}
foreach($rule in $obj.requirementRules)
{
if($rule.'@OData.Type' -eq "#microsoft.graph.win32LobAppPowerShellScriptRequirement")
{
if($rule.ScriptContent)
{
[IO.File]::WriteAllBytes(("$path\$($fi.BaseName)_RequirementScript.ps1"), ([System.Convert]::FromBase64String($rule.ScriptContent)))
}
}
}
}
catch
{
Write-LogError "Failed to export scripts" $_.Exception
}
}
}
function Start-PostListApplications
{
param($objList, $objectType)
foreach($obj in ($objList | Where { $_.Object."@OData.Type" -eq "#microsoft.graph.winGetApp"}))
{
if($obj.Object.packageIdentifier -like "9*")
{
$installerType = "UWP"
}
elseif($obj.Object.packageIdentifier -like "X*")
{
$installerType = "Win32"
}
else
{
$objName = Get-GraphObjectName $obj.Object $objectType
Write-Log "Unknown package identifier for app $($objName): $($obj.Object.packageIdentifier)" 2
$installerType = "Unknown"
}
$obj.Object | Add-Member -MemberType NoteProperty -Name "InstallerType" -Value $installerType
}
$objList
}
#endregion
#region Group Policy/Administrative Templates functions
@@ -2587,6 +2687,21 @@ function Start-PreUpdateSettingsCatalog
@{"Method"="PUT"}
}
function Start-PostGetSettingsCatalog
{
param($obj, $objectType)
if(-not $obj.Object.Assignments)
{
$url = "$($objectType.API)/$($obj.id)/assignments"
$assignments = (Invoke-GraphRequest -Url $url).Value
if($assignments)
{
$obj.Object.Assignments = $assignments
}
}
}
#endregion
#region Notification functions
@@ -2787,6 +2902,19 @@ function Start-PostExportScopeTags
Add-EMAssignmentsToExportFile $obj $objectType $path
}
function Start-PostGetScopeTags
{
param($obj, $objectType)
$strAPI = "$($objectType.API)/$($obj.Object.Id)/assignments"
$tmpObj = Invoke-GraphRequest -Url $strAPI
if(($tmpObj.value | measure).count -gt 0)
{
$obj.Object.assignments = $tmpObj.value
}
}
#endregion
#region AutoPilot
@@ -2856,6 +2984,34 @@ function Start-PreUpdateDeviceHealthScripts
}
}
function Start-PostExportDeviceHealthScripts
{
param($obj, $objectType, $path)
if($global:chkExportScript.IsChecked)
{
$fileName = Get-GraphObjectFile $obj $objectType
$fi = [IO.FileInfo]"$path\$fileName"
try
{
if($obj.detectionScriptContent)
{
[IO.File]::WriteAllBytes(("$path\$($fi.BaseName)_DetectionScript.ps1"), ([System.Convert]::FromBase64String($obj.detectionScriptContent)))
}
if($obj.remediationScriptContent)
{
[IO.File]::WriteAllBytes(("$path\$($fi.BaseName)_RemediationScript.ps1"), ([System.Convert]::FromBase64String($obj.remediationScriptContent)))
}
}
catch
{
Write-LogError "Failed to export scripts" $_.Exception
}
}
}
#endregion
#region Generic functions
@@ -2942,6 +3098,7 @@ function Add-EMAssignmentsToExportFile
Write-Log "File not found: $fileName. Could not add assignments to file" 3
return
}
$tmpObj = Get-GraphObjectFromFile $fileName
if(-not $url)
@@ -3078,6 +3235,17 @@ function Start-PreImportConditionalAccess
{
$obj.state = $global:cbImportCAState.SelectedValue
}
if($obj.grantControls.authenticationStrength)
{
$obj.grantControls.operator = "AND"
$tmpObj = Get-GraphObjectFromFile $file
$authSetting = [PSCustomObject]@{
id = $tmpObj.grantControls.authenticationStrength.id
}
$obj.grantControls.authenticationStrength = $authSetting
}
}
function Start-PostExportConditionalAccess
@@ -3258,4 +3426,33 @@ function Start-PreDeleteADMXFiles
#endregion
#region Reusable Groups
function Start-PostGetReusableSettings
{
param($obj, $objectType)
$strAPI = "$($objectType.API)/$($obj.Object.Id)?`$select=settinginstance,displayname,description"
$tmpObj = Invoke-GraphRequest -Url $strAPI
if($tmpObj.settingInstance)
{
$obj.Object | Add-Member Noteproperty -Name "settingInstance" -Value $tmpObj.settingInstance -Force
}
}
#endregon
#region Authentication Strength
function Start-PreImportCommandAuthenticationStrengths
{
param($obj, $objectType, $file, $assignments)
if($obj.policyType -ne "custom")
{
Write-Log "Built-in Authentication Strength objects cannot be imported" 2
@{ "Import" = $false }
}
}
#endregion
Export-ModuleMember -alias * -function *

View File

@@ -10,7 +10,7 @@ This module manages Authentication for the application with MSAL. It is also res
#>
function Get-ModuleVersion
{
'3.7.4'
'3.8.1'
}
$global:msalAuthenticator = $null
@@ -37,7 +37,7 @@ function Invoke-InitializeModule
Name = "Azure AD China"
Value = "china"
URL = "login.partner.microsoftonline.cn"
GraphURL = "https://microsoftgraph.chinacloudapi.cn"
GraphURL = "microsoftgraph.chinacloudapi.cn"
}
)
@@ -209,16 +209,15 @@ function Set-MSALGraphEnvironment
}
}
}
elseif($cuAADEnv.GraphURL)
elseif($curAADEnv.GraphURL)
{
$graphEnv = $cuAADEnv.GraphURL
$graphEnv = $curAADEnv.GraphURL
}
Write-Log "Use Graph environment: $graphEnv"
$global:MSALGraphEnvironment = $graphEnv
}
function Get-MSALUserInfo
{
if($global:MSALToken)

View File

@@ -10,7 +10,7 @@ This module manages Microsoft Grap fuctions like calling APIs, managing graph ob
#>
function Get-ModuleVersion
{
'3.7.4'
'3.8.1'
}
$global:MSGraphGlobalApps = @(
@@ -460,16 +460,26 @@ function Invoke-GraphRequest
$response = $reader.ReadToEnd() | ConvertFrom-Json
if($response.Error.Message)
{
$message = $response.Error.Message | ConvertFrom-Json
if($message.Message)
$extMessage = $response.Error.Message
try
{
$extMessage = ". Response message: $($message.Message)"
if($response.Error.Message.StartsWith("{") -and $response.Error.Message.EndsWith("}"))
{
$message = $response.Error.Message | ConvertFrom-Json
if($message.Message)
{
$extMessage = ". Response message: $($message.Message)"
}
}
}
catch {}
$extMessage = ". Response message: $($extMessage)"
}
}
catch{}
Write-LogError "Failed to invoke MS Graph with URL $Url (Request ID: $requestId). Status code: $($_.Exception.Response.StatusCode)$extMessage" $_.Excption
Write-LogError "Failed to invoke MS Graph with URL $Url (Request ID: $requestId). Status code: $($_.Exception.Response.StatusCode)$extMessage" $_.Exception
}
}
} while($retryRequest -eq $true)
@@ -1333,6 +1343,18 @@ function Get-GraphBatchObjectTypes
$silentViewObjects
}
function Get-GraphObjectType
{
param($objTypeId)
$intuneView = $global:viewObjects | Where { $_.ViewInfo.Id -eq "IntuneGraphAPI" }
if($intuneView)
{
($intuneView.ViewItems | Where Id -eq $objTypeId)
}
}
function Start-GraphObjectExport
{
Write-Status "Export objects" -Block
@@ -4165,7 +4187,14 @@ function Get-GraphObjectFromFile
$json = $json -replace "%OrganizationId%",$global:Organization.Id
}
$json | ConvertFrom-Json
try
{
$json | ConvertFrom-Json
}
catch
{
Write-LogError "Failed to convert json file $fileName" $_.Exception
}
}
function Save-GraphObjectToFile
@@ -4188,3 +4217,83 @@ function Save-GraphObjectToFile
Write-LogError "Failed to save file $fileName" $_.Exception
}
}
function Get-GraphObjectFile
{
param($obj, $objectType, $path)
$fileName = (Get-GraphObjectName $obj $objectType)
if((Get-SettingValue "AddIDToExportFile") -eq $true -and $obj.Id)
{
$fileName = ($fileName + "_" + $obj.Id)
}
$fileName = "$((Remove-InvalidFileNameChars $fileName)).json"
if($path)
{
$fileName = "$path\$fileName"
}
$fileName
}
function Confirm-GraphMatchFilter
{
param($graphObj, [string]$filter)
if(-not $filter.Trim()) { return $true }
$filterScope = ""
if($filter -like "scope:*" -or $filter -like "tag:*")
{
$filterScope = $filter.Split(':')[1]
}
$objName = Get-GraphObjectName $graphObj.Object $graphObj.ObjectType
if($filterScope)
{
if(($graphObj.Object.PSObject.Properties | Where Name -eq "roleScopeTagIds"))
{
$scopeTagProperty = "roleScopeTagIds"
}
elseif(($graphObj.Object.PSObject.Properties | Where Name -eq "roleScopeTags"))
{
$scopeTagProperty = "roleScopeTags"
}
else
{
Write-Log "$objName excluded based on Scope(Tags) not supported on $($graphObj.ObjectType.GroupId) objects"
continue
}
if(-not $script:scopeTags -and $script:offlineDocumentation -ne $true)
{
$script:scopeTags = (Invoke-GraphRequest -Url "/deviceManagement/roleScopeTags").Value
}
$found = $false
foreach($scopeTagId in $graphObj.Object."$scopeTagProperty")
{
$scopeTagObj = $script:scopeTags | Where Id -eq $scopeTagId
if($scopeTagObj -and $filterScope -and $scopeTagObj.displayName -match [RegEx]::Escape($filterScope))
{
return $true
}
}
if($found -eq $false)
{
Write-Log "$objName excluded based on no Scope(Tags) found that matches the filter"
return $false
}
}
else
{
if($objName -and $filter -and $objName -notmatch [RegEx]::Escape($filter))
{
Write-Log "$objName excluded based on the name does not match the filter"
return $false
}
}
return $true
}