diff --git a/CHANGELOG.md b/CHANGELOG.md index 734102a4d7..c7c3f007af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change log for Microsoft365DSC +# UNRELEASED + +* M365DSCResourceGenerator + * Fix formatting and missing escape character in Resource Generator + # 1.24.605.1 * AADAuthenticationFlowPolicy @@ -7,7 +12,7 @@ * AADEntitlementManagementRoleAssignment * Initial Release. * IntuneAppConfigurationDevicePolicy - * Add assignment group display name and fix compilation + * Add assignment group display name and fix compilation FIXES [#4724](https://github.com/microsoft/Microsoft365DSC/issues/4724) * M365DSCResourceGenerator * Add support for generating Intune settings catalog policies @@ -34,10 +39,10 @@ * IntuneDiskEncryptionMacOS * Initial Release * IntuneSettingCatalogASRRulesPolicyWindows10 - * Add missing properties + * Add missing properties FIXES [#4713](https://github.com/microsoft/Microsoft365DSC/issues/4713) * O365AdminAuditLogConfig - * Fix logging of exception if Set-AdminAuditLogConfig fails + * Fix logging of exception if Set-AdminAuditLogConfig fails FIXES [#4645](https://github.com/microsoft/Microsoft365DSC/issues/4645) * ResourceGenerator * Added `AccessTokens` parameter to PS1 and MOF template @@ -48,22 +53,22 @@ # 1.24.522.1 * IntuneDeviceConfigurationPlatformScriptWindows - * Initial Release - FIXES [#4157](https://github.com/microsoft/Microsoft365DSC/issues/4157) + * Initial Release + FIXES [#4157](https://github.com/microsoft/Microsoft365DSC/issues/4157) * IntuneDeviceConfigurationPlatformScriptMacOS - * Initial Release - FIXES [#4157](https://github.com/microsoft/Microsoft365DSC/issues/4157) + * Initial Release + FIXES [#4157](https://github.com/microsoft/Microsoft365DSC/issues/4157) * IntuneDeviceEnrollmentPlatformRestriction - * Fix missing export of the default policy - FIXES [#4694](https://github.com/microsoft/Microsoft365DSC/issues/4694) + * Fix missing export of the default policy + FIXES [#4694](https://github.com/microsoft/Microsoft365DSC/issues/4694) * IntuneDeviceEnrollmentStatusPageWindows10 * Return all authentication methods when retrieving the policies otherwise it may fail deducing the OrganizationName via TenantId * IntuneDeviceRemediation - * Initial Release + * Initial Release FIXES [#4159](https://github.com/microsoft/Microsoft365DSC/issues/4159) * IntuneWindowsUpdateForBusinessDriverUpdateProfileWindows10 - * Initial Release + * Initial Release FIXES [#3747](https://github.com/microsoft/Microsoft365DSC/issues/3747) * SPOTenantCdnPolicy * If properties in the tenant are empty then export them as empty arrays diff --git a/ResourceGenerator/M365DSCResourceGenerator.psm1 b/ResourceGenerator/M365DSCResourceGenerator.psm1 index 3c5c585ac9..71a21e7ade 100644 --- a/ResourceGenerator/M365DSCResourceGenerator.psm1 +++ b/ResourceGenerator/M365DSCResourceGenerator.psm1 @@ -393,16 +393,16 @@ function New-M365DSCResource { $getAlternativeFilterString.AppendLine(" -Filter `"$alternativeKey eq '`$$alternativeKey'`" ``") | Out-Null $getAlternativeFilterString.AppendLine(" -ErrorAction SilentlyContinue | Where-Object ``") | Out-Null - $getAlternativeFilterString.AppendLine(" -FilterScript { ``") | Out-Null - $getAlternativeFilterString.AppendLine(" `$_.AdditionalProperties.'@odata.type' -eq `"`#microsoft.graph.$SelectedODataType`" ``") | Out-Null + $getAlternativeFilterString.AppendLine(" -FilterScript {") | Out-Null + $getAlternativeFilterString.AppendLine(" `$_.AdditionalProperties.'@odata.type' -eq `"`#microsoft.graph.$SelectedODataType`"") | Out-Null $getAlternativeFilterString.Append(" }") | Out-Null } else { $getAlternativeFilterString.AppendLine(" -ErrorAction SilentlyContinue | Where-Object ``") | Out-Null - $getAlternativeFilterString.AppendLine(" -FilterScript { ``") | Out-Null + $getAlternativeFilterString.AppendLine(" -FilterScript {") | Out-Null $getAlternativeFilterString.AppendLine(" `$_.$alternativeKey -eq `"`$(`$$alternativeKey)`" ``") | Out-Null - $getAlternativeFilterString.AppendLine(" -and `$_.AdditionalProperties.'@odata.type' -eq `"`#microsoft.graph.$SelectedODataType`" ``") | Out-Null + $getAlternativeFilterString.AppendLine(" -and `$_.AdditionalProperties.'@odata.type' -eq `"`#microsoft.graph.$SelectedODataType`"") | Out-Null $getAlternativeFilterString.Append(" }") | Out-Null } Write-TokenReplacement -Token '' -Value $getAlternativeFilterString.ToString() -FilePath $moduleFilePath @@ -477,16 +477,16 @@ function New-M365DSCResource $newDefaultParameterSet = $newCmdlet.ParameterSets | Where-Object -FilterScript { $_.Name -eq 'Create' } [Array]$newKeyIdentifier = ($newDefaultParameterSet.Parameters | Where-Object -FilterScript { $_.IsMandatory }).Name $defaultCreateParameters = @" - `$CreateParameters = ([Hashtable]`$BoundParameters).clone() - `$CreateParameters = Rename-M365DSCCimInstanceParameter -Properties `$CreateParameters - `$CreateParameters.Remove('Id') | Out-Null + `$createParameters = ([Hashtable]`$BoundParameters).clone() + `$createParameters = Rename-M365DSCCimInstanceParameter -Properties `$createParameters + `$createParameters.Remove('Id') | Out-Null - `$keys = (([Hashtable]`$CreateParameters).clone()).Keys + `$keys = (([Hashtable]`$createParameters).clone()).Keys foreach (`$key in `$keys) { - if (`$null -ne `$CreateParameters.`$key -and `$CreateParameters.`$key.getType().Name -like '*cimInstance*') + if (`$null -ne `$createParameters.`$key -and `$createParameters.`$key.GetType().Name -like '*CimInstance*') { - `$CreateParameters.`$key = Convert-M365DSCDRGComplexTypeToHashtable -ComplexObject `$CreateParameters.`$key + `$createParameters.`$key = Convert-M365DSCDRGComplexTypeToHashtable -ComplexObject `$createParameters.`$key } } "@ @@ -499,7 +499,7 @@ function New-M365DSCResource `$keys = (([Hashtable]`$UpdateParameters).clone()).Keys foreach (`$key in `$keys) { - if (`$null -ne `$UpdateParameters.`$key -and `$UpdateParameters.`$key.getType().Name -like '*cimInstance*') + if (`$null -ne `$UpdateParameters.`$key -and `$UpdateParameters.`$key.GetType().Name -like '*CimInstance*') { `$UpdateParameters.`$key = Convert-M365DSCDRGComplexTypeToHashtable -ComplexObject `$UpdateParameters.$key } @@ -520,16 +520,17 @@ function New-M365DSCResource $keyValue = $key if ($key -eq 'BodyParameter') { - $keyValue = 'CreateParameters' + $keyValue = 'createParameters' } $newParameterString.Append("-$key `$$keyValue") | Out-Null } [String]$newKeyIdentifier = $newParameterString.ToString() } + $odataType = $null if ($true)#$isAdditionalProperty) { - $odataType = " `$CreateParameters.Add(`"@odata.type`", `"#microsoft.graph.$SelectedODataType`")`r`n" + $odataType = " `$createParameters.Add(`"@odata.type`", `"#microsoft.graph.$SelectedODataType`")`r`n" } $settingsCatalogProperties = "" @@ -544,14 +545,14 @@ function New-M365DSCResource "@ $defaultCreateParameters = @" - `$settings = Get-IntuneSettingCatalogPolicySetting ` - -DSCParams ([System.Collections.Hashtable]`$BoundParameters) ` + `$settings = Get-IntuneSettingCatalogPolicySetting `` + -DSCParams ([System.Collections.Hashtable]`$BoundParameters) `` -TemplateId `$templateReferenceId - `$CreateParameters = @{ + `$createParameters = @{ Name = `$DisplayName Description = `$Description - TemplateReference = @{templateId = `$templateReferenceId } + TemplateReference = @{ templateId = `$templateReferenceId } Platforms = `$platforms Technologies = `$technologies Settings = `$settings @@ -586,15 +587,15 @@ function New-M365DSCResource if ($isAdditionalProperty -and $CmdletNoun -notlike "*DeviceManagementConfigurationPolicy") { $exportGetCommand.AppendLine(" -ErrorAction Stop | Where-Object ``") | Out-Null - $exportGetCommand.AppendLine(" -FilterScript { ``") | Out-Null - $exportGetCommand.AppendLine(" `$_.AdditionalProperties.'@odata.type' -eq '#microsoft.graph.$($selectedODataType)' ``") | Out-Null + $exportGetCommand.AppendLine(" -FilterScript {") | Out-Null + $exportGetCommand.AppendLine(" `$_.AdditionalProperties.'@odata.type' -eq '#microsoft.graph.$($selectedODataType)'") | Out-Null $exportGetCommand.AppendLine(" }") | Out-Null } elseif ($CmdletNoun -like "*DeviceManagementConfigurationPolicy") { $exportGetCommand.AppendLine(" -ErrorAction Stop | Where-Object ``") | Out-Null - $exportGetCommand.AppendLine(" -FilterScript { ``") | Out-Null - $exportGetCommand.AppendLine(" `$_.TemplateReference.TemplateId -eq `$policyTemplateID ``") | Out-Null + $exportGetCommand.AppendLine(" -FilterScript {") | Out-Null + $exportGetCommand.AppendLine(" `$_.TemplateReference.TemplateId -eq `$policyTemplateID") | Out-Null $exportGetCommand.AppendLine(" }") | Out-Null } else @@ -668,17 +669,17 @@ function New-M365DSCResource $updateKeyIdentifier = "" $updateCmdletName = "" $defaultUpdateParameters = @" - `$settings = Get-IntuneSettingCatalogPolicySetting ` - -DSCParams ([System.Collections.Hashtable]`$BoundParameters) ` + `$settings = Get-IntuneSettingCatalogPolicySetting `` + -DSCParams ([System.Collections.Hashtable]`$BoundParameters) `` -TemplateId `$templateReferenceId - Update-DeviceManagementConfigurationPolicy ` - -DeviceManagementConfigurationPolicyId `$currentInstance.Id ` - -DisplayName `$DisplayName ` - -Description `$Description ` - -TemplateReference `$templateReferenceId ` - -Platforms `$platforms ` - -Technologies `$technologies ` + Update-IntuneDeviceConfigurationPolicy `` + -DeviceConfigurationPolicyId `$currentInstance.Id `` + -Name `$DisplayName `` + -Description `$Description `` + -TemplateReferenceId `$templateReferenceId `` + -Platforms `$platforms `` + -Technologies `$technologies `` -Settings `$settings`r`n "@ } @@ -733,12 +734,13 @@ function New-M365DSCResource $AssignmentsNew += " `$assignmentsHash = @()`r`n" $AssignmentsNew += " foreach (`$assignment in `$Assignments)`r`n" $AssignmentsNew += " {`r`n" - $AssignmentsNew += " `$assignmentsHash += Get-M365DSCDRGComplexTypeToHashtable -ComplexObject `$Assignment`r`n" + $AssignmentsNew += " `$assignmentsHash += Get-M365DSCDRGComplexTypeToHashtable -ComplexObject `$assignment`r`n" $AssignmentsNew += " }`r`n" $AssignmentsNew += "`r`n" $AssignmentsNew += " if (`$policy.Id)`r`n" $AssignmentsNew += " {`r`n" - $AssignmentsNew += " Update-DeviceConfigurationPolicyAssignment -DeviceConfigurationPolicyId `$policy.Id ```r`n" + $AssignmentsNew += " Update-DeviceConfigurationPolicyAssignment ```r`n" + $AssignmentsNew += " -DeviceConfigurationPolicyId `$policy.Id ```r`n" $AssignmentsNew += " -Targets `$assignmentsHash ```r`n" $AssignmentsNew += " -Repository '$repository'`r`n" $AssignmentsNew += " }`r`n" @@ -746,12 +748,12 @@ function New-M365DSCResource $AssignmentsUpdate += " `$assignmentsHash = @()`r`n" $AssignmentsUpdate += " foreach (`$assignment in `$Assignments)`r`n" $AssignmentsUpdate += " {`r`n" - $AssignmentsUpdate += " `$assignmentsHash += Get-M365DSCDRGComplexTypeToHashtable -ComplexObject `$Assignment`r`n" + $AssignmentsUpdate += " `$assignmentsHash += Get-M365DSCDRGComplexTypeToHashtable -ComplexObject `$assignment`r`n" $AssignmentsUpdate += " }`r`n" $AssignmentsUpdate += " Update-DeviceConfigurationPolicyAssignment ```r`n" $AssignmentsUpdate += " -DeviceConfigurationPolicyId `$currentInstance.Id ```r`n" $AssignmentsUpdate += " -Targets `$assignmentsHash ```r`n" - $AssignmentsUpdate += " -Repository '$repository'`r`n" + $AssignmentsUpdate += " -Repository '$repository'" $AssignmentsCIM = @' [ClassVersion("1.0.0.0")] @@ -766,9 +768,9 @@ class MSFT_DeviceManagementConfigurationPolicyAssignments }; '@ - $AssignmentsProperty = " [Write, Description(`"Represents the assignment to the Intune policy.`"), EmbeddedInstance(`"MSFT_DeviceManagementConfigurationPolicyAssignments`")] String Assignments[];`r`n" + $AssignmentsProperty = "`r`n [Write, Description(`"Represents the assignment to the Intune policy.`"), EmbeddedInstance(`"MSFT_DeviceManagementConfigurationPolicyAssignments`")] String Assignments[];`r`n" $AssignmentsConvertComplexToString = @" - if (`$Results.Assignments) +`r`n if (`$Results.Assignments) { `$complexTypeStringResult = Get-M365DSCDRGComplexTypeToString -ComplexObject `$Results.Assignments -CIMInstanceName DeviceManagementConfigurationPolicyAssignments if (`$complexTypeStringResult) @@ -779,14 +781,13 @@ class MSFT_DeviceManagementConfigurationPolicyAssignments { `$Results.Remove('Assignments') | Out-Null } - } + }`r`n "@ $AssignmentsConvertComplexToVariable = @" - if (`$Results.Assignments) +`r`n if (`$Results.Assignments) { - `$currentDSCBlock = Convert-DSCStringParamToVariable -DSCBlock `$currentDSCBlock -ParameterName "Assignments" -isCIMArray:`$true - } - + `$currentDSCBlock = Convert-DSCStringParamToVariable -DSCBlock `$currentDSCBlock -ParameterName "Assignments" -IsCIMArray:`$true + }`r`n "@ } Write-TokenReplacement -Token '' -Value $AssignmentsParam -FilePath $moduleFilePath @@ -811,27 +812,7 @@ class MSFT_DeviceManagementConfigurationPolicyAssignments `$ValuesToCheck.Add(`$_.Key, `$null) if (-not `$PSBoundParameters.ContainsKey(`$_.Key)) { - `$value = `$null - switch (`$CurrentValues[`$_.Key].GetType().Name) - { - 'Boolean' - { - `$value = `$false - } - 'String' - { - `$value = '' - } - 'Int32' - { - `$value = 0 - } - 'String[]' - { - `$value = @() - } - } - `$PSBoundParameters.Add(`$_.Key, `$value) + `$PSBoundParameters.Add(`$_.Key, `$null) } } } @@ -3310,7 +3291,7 @@ function New-M365HashTableMapping $convertToVariable += " if (`$Results.$parameterName)`r`n" $convertToVariable += " {`r`n" - $convertToVariable += " `$currentDSCBlock = Convert-DSCStringParamToVariable -DSCBlock `$currentDSCBlock -ParameterName `"$parameterName`" -isCIMArray:`$$($property.IsArray)`r`n" + $convertToVariable += " `$currentDSCBlock = Convert-DSCStringParamToVariable -DSCBlock `$currentDSCBlock -ParameterName `"$parameterName`" -IsCIMArray:`$$($property.IsArray)`r`n" $convertToVariable += " }`r`n" } if ($property.IsEnumType) @@ -3782,8 +3763,9 @@ function New-SettingsCatalogSettingDefinitionSettingsFromTemplate { $childSettings = @() $childSettings += $SettingTemplate.SettingDefinitions | Where-Object -FilterScript { - ($_.AdditionalProperties.dependentOn.Count -gt 0 -and $_.AdditionalProperties.dependentOn.parentSettingId.Contains($SettingDefinition.Id)) -or - ($_.AdditionalProperties.options.dependentOn.Count -gt 0 -and $_.AdditionalProperties.options.dependentOn.parentSettingId.Contains($SettingDefinition.Id)) + $_.visibility -notlike "*none*" -and + (($_.AdditionalProperties.dependentOn.Count -gt 0 -and $_.AdditionalProperties.dependentOn.parentSettingId.Contains($SettingDefinition.Id)) -or + ($_.AdditionalProperties.options.dependentOn.Count -gt 0 -and $_.AdditionalProperties.options.dependentOn.parentSettingId.Contains($SettingDefinition.Id))) } $setting = [ordered]@{ @@ -3830,7 +3812,7 @@ function New-ParameterDefinitionFromSettingsCatalogTemplateSetting { "SimpleIntegerCollection" = "System.Int32[]" } - $mofParameterTemplate = " [Write, Description("" "")] ;" + $mofParameterTemplate = " [Write, Description("""")] ;" $powerShellParameterTemplate = @" [Parameter()] [] @@ -3838,6 +3820,8 @@ function New-ParameterDefinitionFromSettingsCatalogTemplateSetting { "@ $mofDefinition = $mofParameterTemplate.Replace("", $TemplateSetting.DisplayName) + $optionsString = "" + $valueMapString = "" if ($TemplateSetting.Options) { $options = @() $values = @() @@ -3845,11 +3829,11 @@ function New-ParameterDefinitionFromSettingsCatalogTemplateSetting { $options += "$($_.Id)" + ": " + $_.Name.Replace("""", "'") $values += """$($_.Id)""" } - $optionsString = "(" + ($options -join ", ") + ")" - $ValueMapString = ", ValueMap{$($values -join ", ")}, Values{$($values -join ", ")}" + $optionsString = " (" + ($options -join ", ") + ")" + $valueMapString = ", ValueMap{$($values -join ", ")}, Values{$($values -join ", ")}" } $mofDefinition = $mofDefinition.Replace("", $optionsString) - $mofDefinition = $mofDefinition.Replace("", $ValueMapString) + $mofDefinition = $mofDefinition.Replace("", $valueMapString) $mofDefinition = $mofDefinition.Replace("", $mofTypeMapping[$TemplateSetting.Type]) $mofDefinition = $mofDefinition.Replace("", $TemplateSetting.Name) $isCollection = $TemplateSetting.Type -like "*Collection" diff --git a/ResourceGenerator/Module.Template.psm1 b/ResourceGenerator/Module.Template.psm1 index a03262750a..9b37ea5980 100644 --- a/ResourceGenerator/Module.Template.psm1 +++ b/ResourceGenerator/Module.Template.psm1 @@ -69,7 +69,7 @@ function Get-TargetResource { Write-Verbose -Message "Could not find an with {$}" - if (-not [string]::IsNullOrEmpty($)) + if (-not [System.String]::IsNullOrEmpty($)) { $getValue = ` @@ -78,11 +78,11 @@ function Get-TargetResource #endregionResourceGenerator#> if ($null -eq $getValue) { - Write-Verbose -Message "Could not find an with {$}" + Write-Verbose -Message "Could not find an with {$}." return $nullResult } $ = $getValue. - Write-Verbose -Message "An with {$} and {$} was found."<#ResourceGenerator + Write-Verbose -Message "An with {$} and {$} was found"<#ResourceGenerator ResourceGenerator#> $results = @{<#ResourceGenerator #region resource generator code @@ -176,12 +176,12 @@ function Set-TargetResource <#AssignmentsRemove#> <#DefaultUpdateParameters#><#ResourceGenerator #region resource generator code - <#UpdateKeyIdentifier#> -<#AssignmentsUpdate#> #endregionResourceGenerator#> +<#UpdateKeyIdentifier#><#AssignmentsUpdate#> + #endregionResourceGenerator#> } elseif ($Ensure -eq 'Absent' -and $currentInstance.Ensure -eq 'Present') { - Write-Verbose -Message "Removing the with {$($currentInstance.)}" <#ResourceGenerator + Write-Verbose -Message "Removing the with {$($currentInstance.)}"<#ResourceGenerator #region resource generator code <#removeKeyIdentifier#> #endregionResourceGenerator#>