ironmansoftware / powershell-universal

Issue tracker for PowerShell Universal
https://powershelluniversal.com
37 stars 4 forks source link

Enabling or disabling Configuration File Splatting in existing PSU environment results in improperly formatted config files #3800

Closed JessePeden closed 1 month ago

JessePeden commented 1 month ago

Version

5.0.7

Severity

Critical

Environment

msi

Steps to Reproduce

  1. Toggle Configuration File Splatting off or on.
  2. Add something new to PSU or modify an existing entry.
  3. View the configuration file for the corresponding type of change (i.e., if you added a script, look at the scripts.ps1 file).

Expected behavior

Enabling or disabling Configuration File Splatting should immediately change the configuration files rather than only doing it upon PSU's configurations being changed next (such as adding a new script or scheduled task).

Actual behavior

Enabling/disabling Configuration File Splatting in an existing environment results in configuration files that have a combination of non-Splatting and Splatting, but the changes to the configuration files of either using/not-using splatting are not immediately noticed due to PSU only modifying the configuration files when a configuration change is made (such as adding a new script or scheduled task), rather than immediately splatting or un-splatting a configuration file at the time the option is toggled on/off.  This results in PSU showing multiple errors about invalid configuration entries, etc. that render PSU unusable until the issues are resolved outside of PSU (via editing the configuration files accordingly to remove the parts that are in the "old" format).

It also seems to do something weird where it adds some Git headers and footers into the files, but I'm not sure if that's Configuration File Splatting doing that or something else.  I've never seen it do that prior to enabling the feature, though.

Example

This is an example of my scripts.ps1 file after enabling Configuration File Splatting:

<<<<<<< HEAD
New-PSUScript -Name "PLC - Get Mist Clients.ps1" -Description "PLC - Get Mist Clients.ps1" -Tag @('PLC') -Path "Mist\PLC - Get Mist Clients.ps1" -InformationAction "SilentlyContinue" -DiscardPipeline 
New-PSUScript -Name "Map 365 Tenants.ps1" -Description "Map 365 Tenants.ps1" -Path "Hudu\Map 365 Tenants.ps1" -Environment "PowerShell 7" -InformationAction "SilentlyContinue" 
New-PSUScript -Name "M365DocsAutomation.ps1" -Description "M365Automation.ps1" -Path "Hudu Dashboards\M365DocsAutomation.ps1" -ErrorAction "SilentlyContinue" -InformationAction "SilentlyContinue" 
New-PSUScript -Name "WarrantyUpdate.ps1" -Description "Update Warranty of Workstations in Hudu" -Path "Hudu\WarrantyUpdate.ps1" -ErrorAction "SilentlyContinue" -InformationAction "SilentlyContinue" 
New-PSUScript -Name "CleanupLiongardServerNames.ps1" -Description "Removes the `"Windows -`" in front of the server name" -Path "Hudu\Housekeeping\CleanupLiongardServerNames.ps1" -Environment "PowerShell 7" -InformationAction "SilentlyContinue" 
New-PSUScript -Name "SpecificClientsM365DocsAutomation.ps1" -Description "Runs specific clients M365 automation, useful for quicker running and testing" -Path "Hudu\SpecificClientsM365DocsAutomation.ps1" -ErrorAction "SilentlyContinue" -InformationAction "SilentlyContinue" 
New-PSUScript -Name "DownloadPaloAltoConfig.ps1" -Description "DownloadPaloAltoConfig.ps1 [[-HuduDeviceID] <string>] [[-HuduCompanyID] <string>] [[-PaloAltoDeviceIP] <string>] [[-PaloAltoAPIKey] <string>]" -Path "Hudu\DownloadPaloAltoConfig.ps1" -InformationAction "SilentlyContinue" 
New-PSUScript -Name "JobFail.ps1" -Description "JobFail.ps1" -Path "Alerts\JobFail.ps1" -InformationAction "SilentlyContinue" 
New-PSUScript -Name "AddMissingWebsites.ps1" -Description "Adds Domains Synced from Liongard into Websites in Hudu for Expirations" -Path "Hudu\Housekeeping\AddMissingWebsites.ps1" -InformationAction "SilentlyContinue" 
New-PSUScript -Name "HCGDocsM365Automation.ps1" -Description "Updates HCG's Hudu Instance (<redacted>) with M365 data using ASI's MS API" -Path "Hudu\HCGDocsM365Automation.ps1" -ErrorAction "SilentlyContinue" -InformationAction "SilentlyContinue" 
New-PSUScript -Name "HuduMagicDashCompanyServices.ps1" -Description "Creates dashboards for each client if a `"Company Service`" is completed in Hudu. " -Path "Hudu\HuduMagicDashCompanyServices.ps1" -InformationAction "SilentlyContinue" 
New-PSUScript -Name "VeeamBackupStatus.ps1" -Description "VeeamBackupStatus.ps1" -Path "Hudu Dashboards\VeeamBackupStatus.ps1" 
New-PSUScript -Name "PrintSecrets.ps1" -Description "PrintSecrets.ps1" -Path "Hudu\Housekeeping\PrintSecrets.ps1" 
New-PSUScript -Name "Bulk Add Zones.ps1" -Description "Bulk Add Zones.ps1" -Path "Cloudflare\Bulk Add Zones.ps1" 
New-PSUScript -Name "BulkUpdateFields.ps1" -Description "BulkUpdateFields.ps1" -Path "Hudu\Housekeeping\BulkUpdateFields.ps1" 
New-PSUScript -Name "BulkDownloadPaloAltoConfig.ps1" -Description "BulkDownloadPaloAltoConfig.ps1" -Path "Hudu\BulkDownloadPaloAltoConfig.ps1" 
New-PSUScript -Name "PGF - Get Mist Clients.ps1" -Description "PGF - Get Mist Clients.ps1" -Tag @('Progressive') -Path "Mist\PGF - Get Mist Clients.ps1" -DiscardPipeline 
New-PSUScript -Name "Dashboard-Liongard.ps1" -Description "Dashboard-Liongard.ps1" -Path "Hudu Dashboards\Dashboard-Liongard.ps1"
New-PSUScript -Name "Dashboard-M365.ps1" -Description "Dashboard-M365.ps1" -Path "Hudu Dashboards\Dashboard-M365.ps1"
New-PSUScript -Name "Dashboard-Veeam.ps1" -Description "Dashboard-Veeam.ps1" -Path "Hudu Dashboards\Dashboard-Veeam.ps1"
New-PSUScript -Name "LiongardOpenAlerts.ps1" -Description "LiongardOpenAlerts.ps1" -Path "Hudu Dashboards\LiongardOpenAlerts.ps1"
=======
$Parameters = @{
    Name              = "PLC - Get Mist Clients.ps1"
    Description       = "PLC - Get Mist Clients.ps1"
    Tag               = @('PLC')
    Path              = "Mist\PLC - Get Mist Clients.ps1"
    InformationAction = "SilentlyContinue"
    DiscardPipeline   = $true
}
New-PSUScript @Parameters
$Parameters = @{
    Name              = "Map 365 Tenants.ps1"
    Description       = "Map 365 Tenants.ps1"
    Path              = "Hudu\Map 365 Tenants.ps1"
    Environment       = "PowerShell 7"
    InformationAction = "SilentlyContinue"
}
New-PSUScript @Parameters
$Parameters = @{
    Name              = "Dashboard-M365.ps1"
    Description       = "M365Automation.ps1"
    Path              = "dashboards\M365DocsAutomation.ps1"
    ErrorAction       = "SilentlyContinue"
    InformationAction = "SilentlyContinue"
}
New-PSUScript @Parameters
$Parameters = @{
    Name              = "WarrantyUpdate.ps1"
    Description       = "Update Warranty of Workstations in Hudu"
    Path              = "Hudu\WarrantyUpdate.ps1"
    ErrorAction       = "SilentlyContinue"
    InformationAction = "SilentlyContinue"
}
New-PSUScript @Parameters
$Parameters = @{
    Name              = "CleanupLiongardServerNames.ps1"
    Description       = "Removes the `"Windows -`" in front of the server name"
    Path              = "Hudu\Housekeeping\CleanupLiongardServerNames.ps1"
    Environment       = "PowerShell 7"
    InformationAction = "SilentlyContinue"
}
New-PSUScript @Parameters
$Parameters = @{
    Name              = "SpecificClientsM365DocsAutomation.ps1"
    Description       = "Runs specific clients M365 automation, useful for quicker running and testing"
    Path              = "Hudu\SpecificClientsM365DocsAutomation.ps1"
    ErrorAction       = "SilentlyContinue"
    InformationAction = "SilentlyContinue"
}
New-PSUScript @Parameters
$Parameters = @{
    Name              = "DownloadPaloAltoConfig.ps1"
    Description       = "DownloadPaloAltoConfig.ps1 [[-HuduDeviceID] <string>] [[-HuduCompanyID] <string>] [[-PaloAltoDeviceIP] <string>] [[-PaloAltoAPIKey] <string>]"
    Path              = "Hudu\DownloadPaloAltoConfig.ps1"
    InformationAction = "SilentlyContinue"
}
New-PSUScript @Parameters
$Parameters = @{
    Name              = "JobFail.ps1"
    Description       = "JobFail.ps1"
    Path              = "Alerts\JobFail.ps1"
    InformationAction = "SilentlyContinue"
}
New-PSUScript @Parameters
$Parameters = @{
    Name              = "AddMissingWebsites.ps1"
    Description       = "Adds Domains Synced from Liongard into Websites in Hudu for Expirations"
    Path              = "Hudu\Housekeeping\AddMissingWebsites.ps1"
    InformationAction = "SilentlyContinue"
}
New-PSUScript @Parameters
$Parameters = @{
    Name              = "HCGDocsM365Automation.ps1"
    Description       = "Updates HCG's Hudu Instance (<redacted>) with M365 data using ASI's MS API"
    Path              = "Hudu\HCGDocsM365Automation.ps1"
    ErrorAction       = "SilentlyContinue"
    InformationAction = "SilentlyContinue"
}
New-PSUScript @Parameters
$Parameters = @{
    Name              = "HuduMagicDashCompanyServices.ps1"
    Description       = "Creates dashboards for each client if a `"Company Service`" is completed in Hudu. "
    Path              = "Hudu\HuduMagicDashCompanyServices.ps1"
    InformationAction = "SilentlyContinue"
}
New-PSUScript @Parameters
$Parameters = @{
    Name        = "Dashboard-Veeam"
    Description = "VeeamBackupStatus.ps1"
    Path        = "dashboards\VeeamBackupStatus.ps1"
}
New-PSUScript @Parameters
$Parameters = @{
    Name        = "PrintSecrets.ps1"
    Description = "PrintSecrets.ps1"
    Path        = "Hudu\Housekeeping\PrintSecrets.ps1"
}
New-PSUScript @Parameters
$Parameters = @{
    Name        = "Bulk Add Zones.ps1"
    Description = "Bulk Add Zones.ps1"
    Path        = "Cloudflare\Bulk Add Zones.ps1"
}
New-PSUScript @Parameters
$Parameters = @{
    Name        = "BulkUpdateFields.ps1"
    Description = "BulkUpdateFields.ps1"
    Path        = "Hudu\Housekeeping\BulkUpdateFields.ps1"
}
New-PSUScript @Parameters
$Parameters = @{
    Name        = "BulkDownloadPaloAltoConfig.ps1"
    Description = "BulkDownloadPaloAltoConfig.ps1"
    Path        = "Hudu\BulkDownloadPaloAltoConfig.ps1"
}
New-PSUScript @Parameters
$Parameters = @{
    Name            = "PGF - Get Mist Clients.ps1"
    Description     = "PGF - Get Mist Clients.ps1"
    Tag             = @('Progressive')
    Path            = "Mist\PGF - Get Mist Clients.ps1"
    DiscardPipeline = $true
}
New-PSUScript @Parameters
$Parameters = @{
    Name        = "Dashboard-Liongard"
    Description = "LiongardOpenAlerts.ps1"
    Path        = "dashboards\LiongardOpenAlerts.ps1"
}
New-PSUScript @Parameters
>>>>>>> origin/main

Additional Environment data

No response

Screenshots/Animations

No response

adamdriscoll commented 1 month ago

This is a merge conflict generated by the git client. I'll see what we can do about that but it's less about the splatting change and more about the changes on the remote vs the local repo.

JessePeden commented 1 month ago

This is a merge conflict generated by the git client. I'll see what we can do about that but it's less about the splatting change and more about the changes on the remote vs the local repo.

Whatever it is, it only seems to have happened when CFS was turned on and at the next change to a configuration file, and it causes PSU to freak out.

adamdriscoll commented 1 month ago

What likely happened was that the file was updated then the git client did a pull from the remote and updated the file with the merge conflict. You have automatic mode on for git, right?

Either way, PSU should handle this more gracefully...

JessePeden commented 1 month ago

You have automatic mode on for git, right?

Yes.