I have a powershell Array object that is programmatically generated, something with arrays inside arrays, inside arrays, sometimes called a "property bag" or a "hashtable", but I think it's natively called an "Array containing Arrays" in the most native powershell terminology.
For example:
@{
Version = '1.0.0'
Name = 'thing'
Revision = 'c3a89cd20e19bb82f41e95e0806edc5b6cfd224e'
Date = '2016-12-09'
Build = '1234'
Contents = @{
"index.html" = "23dd7b993f40bb3ae8848fe104b3b767"
}
}
Generating a function to save only one specific set of contents to a .PSD1 file seems not general enough.
I want to save that exact in-memory Array structure to a PSD1 file. Does any built-in way in Powershell exist to Persist an in-memory variable with the values above? The "opposite function" of Import-PowershellDataFile. I would have guessed it would be called Export-PowershellDatafile but no such function seems to exist.
Have you tried using
New-ModuleManifest? Without knowing any additional details, it appears that you're creating something substantially similar to a manifest file used in a module... But even if your use case is different, you should still be able to use the cmdlet.New-ModuleManifesthas been around for a while (at least since v3, but I seem to recall using it with v2 as well). It allows you to define a hashtable of properties and save it down as a.psd1.https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/new-modulemanifest?view=powershell-5.1