Skip to content

ConvertFrom-DscObject: Append a new line after each resource#81

Merged
FabienTschanz merged 2 commits into
Microsoft365DSC:devfrom
ricmestre:master
Mar 30, 2026
Merged

ConvertFrom-DscObject: Append a new line after each resource#81
FabienTschanz merged 2 commits into
Microsoft365DSC:devfrom
ricmestre:master

Conversation

@ricmestre
Copy link
Copy Markdown
Contributor

Currently ConvertFrom-DscObject doesn't append a new line after each resource which results in something like the below so I've just added a one-liner fix to append Environment.NewLine just right at the end of processing each resource. I've also included a test for this and all tests passed, including mine, with dotnet run

ResourceName "Resource1"
{
    [...]
}ResourceName "Resource2"
{
    [...]
}ResourceName "Resource3"
{
    [...]
}[...]

@FabienTschanz
Copy link
Copy Markdown
Collaborator

Thank you @ricmestre, will review it once I get home from Seattle.

@FabienTschanz
Copy link
Copy Markdown
Collaborator

FabienTschanz commented Mar 30, 2026

Hmm, for me it does what is expected, whether it is in Windows PowerShell or in PowerShell 7. How do you get that result? I'm using e.g. the following code, which gives the correct output:

PS> ConvertTo-DSCObject -Path 'D:\M365DSC\M365DSC_Data\EXO\M365TenantConfig_EXO.ps1' | ConvertFrom-DSCObject

EXORoleGroup "EXORoleGroup-SecurityReaders_590827472"
{
    ApplicationId         = $ConfigurationData.NonNodeData.ApplicationId
    CertificateThumbprint = $ConfigurationData.NonNodeData.CertificateThumbprint
    Description           = "Membership in this role group is synchronized across services and managed centrally. This role group is not manageable through the administrator portals. Members of this role group may include cross-service administrators, as well as external partner groups and Microsoft Support. By default, this group may not be assigned any roles. However, it will be a member of the Security Reader role groups and will inherit the capabilities of that role group."
    Ensure                = "Present"
    Members               = @()
    Name                  = "SecurityReaders_590827472"
    Roles                 = @()
    TenantId              = $OrganizationName
}
EXORoleGroup "EXORoleGroup-Nuvolu_M365DSC_Rolegroup_EXO"
{
    ApplicationId         = $ConfigurationData.NonNodeData.ApplicationId
    CertificateThumbprint = $ConfigurationData.NonNodeData.CertificateThumbprint
    Description           = ""
    Ensure                = "Present"
    Members               = @("Sample")
    Name                  = "Sample"
    Roles                 = @(
        "Mail Recipients"
        "E-Mail Address Policies"
        "Federated Sharing"
        "Mail Tips"
        "Compliance Admin"
        "Address Lists"
        "Organization Configuration"
        "Role Management"
    )
    TenantId              = $OrganizationName
}
EXOSafeAttachmentPolicy "EXOSafeAttachmentPolicy-Standard Preset Security Policy1740412545615"
{
    Action                = "Block"
    AdminDisplayName      = ""
    ApplicationId         = $ConfigurationData.NonNodeData.ApplicationId
    CertificateThumbprint = $ConfigurationData.NonNodeData.CertificateThumbprint
    Enable                = $True
    Ensure                = "Present"
    Identity              = "Standard Preset Security Policy1740412545615"
    QuarantineTag         = "AdminOnlyAccessPolicy"
    Redirect              = $False
    RedirectAddress       = ""
    TenantId              = $OrganizationName
}

Edit: Any chance there is a replace of \r\n or something like that happening somewhere in your code? I'm using DSCParser 3.0.0.1 without any changes.

@ricmestre
Copy link
Copy Markdown
Contributor Author

AH! If you pass the objs via a pipeline it works, I just confirmed, but instead try it with ConvertFrom-DSCObject -DSCResources $Resources

Another thing is that ConvertTo-DscObject doesn't support relative paths so it tries to search for the file in C:\WINDOWS\system32 and of course fails because the file isn't there.

$Resources = ConvertTo-DSCObject -Path .\Config\M365Configuration.ps1
ConvertTo-DSCObject : Error parsing DSC configuration: Exception calling "ConvertToDscObject" with "4" argument(s): "Could not find file 'C:\WINDOWS\system32\Config\M365Configuration.ps1'."
``

@FabienTschanz
Copy link
Copy Markdown
Collaborator

Good catches. I'll test the impact of your change and make sure that support for relative paths is added. Appreciate it!

@FabienTschanz FabienTschanz merged commit 0a04ad5 into Microsoft365DSC:dev Mar 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants