From ad71ad3665d939d6de2bac73a98c31d3dd176e56 Mon Sep 17 00:00:00 2001 From: Alex Floca Date: Wed, 11 Sep 2024 12:31:31 +0200 Subject: [PATCH] Fix ressource --- .../MSFT_SCRoleGroup/MSFT_SCRoleGroup.psm1 | 25 ++++++++++++++++++- .../MSFT_SCRoleGroup.schema.mof | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_SCRoleGroup/MSFT_SCRoleGroup.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_SCRoleGroup/MSFT_SCRoleGroup.psm1 index 5533d71d2f..14c3e57243 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_SCRoleGroup/MSFT_SCRoleGroup.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_SCRoleGroup/MSFT_SCRoleGroup.psm1 @@ -9,6 +9,10 @@ function Get-TargetResource [System.String] $Name, + [Parameter()] + [System.String] + $DisplayName, + [Parameter()] [System.String] $Description, @@ -95,8 +99,9 @@ function Get-TargetResource { $result = @{ Name = $RoleGroup.Name + DisplayName = $RoleGroup.DisplayName Description = $RoleGroup.Description - Roles = $RoleGroup.Roles + Roles = $RoleGroup.Roles -replace "^.*\/(?=[^\/]*$)" Ensure = 'Present' Credential = $Credential ApplicationId = $ApplicationId @@ -134,6 +139,11 @@ function Set-TargetResource [System.String] $Name, + [Parameter()] + [ValidateLength(1, 256)] + [System.String] + $DisplayName, + [Parameter()] [System.String] $Description, @@ -205,6 +215,14 @@ function Set-TargetResource Roles = $Roles Confirm = $false } + # Add DisplayName Parameter equals Name if null or Empty as creation with no value will lead to a corrupted state of the created RoleGroup + if ([System.String]::IsNullOrEmpty($DisplayName)) + { + $NewRoleGroupParams.Add('DisplayName', $Name) + } + else { + $NewRoleGroupParams.Add('DisplayName', $DisplayName) + } # Remove Description Parameter if null or Empty as the creation fails with $null parameter if ([System.String]::IsNullOrEmpty($Description)) { @@ -240,6 +258,11 @@ function Test-TargetResource [System.String] $Name, + [Parameter()] + [ValidateLength(1, 256)] + [System.String] + $DisplayName, + [Parameter()] [System.String] $Description, diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_SCRoleGroup/MSFT_SCRoleGroup.schema.mof b/Modules/Microsoft365DSC/DSCResources/MSFT_SCRoleGroup/MSFT_SCRoleGroup.schema.mof index 9348360605..f4c0b669a4 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_SCRoleGroup/MSFT_SCRoleGroup.schema.mof +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_SCRoleGroup/MSFT_SCRoleGroup.schema.mof @@ -2,6 +2,7 @@ class MSFT_SCRoleGroup : OMI_BaseResource { [Key, Description("The Name parameter specifies the name of the role. The maximum length of the name is 64 characters.")] String Name; + [Write, Description("The DisplayName parameter specifies the name of the role. The maximum length of the name is 256 characters.")] String DisplayName; [Write, Description("The Description parameter specifies the description that's displayed when the role group is viewed using the Get-RoleGroup cmdlet. Enclose the description in quotation marks")] String Description; [Write, Description("The Roles parameter specifies the management roles to assign to the role group when it's created. If a role name contains spaces, enclose the name in quotation marks. If you want to assign more that one role, separate the role names with commas.")] String Roles[]; [Write, Description("Specify if the Role Group should exist or not."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;