Syntax-wise, the closest equivalent is to use a .psd1
file containing a PowerShell hashtable literal, which you can read into an in-memory hashtable using Import-PowerShellDataFile
.
However, note that - as of PowerShell 7.3.1 - there is no way to create such a file programmatically - GitHub issue #11300 discusses future enhancements to allow this.
This answer provides custom code for writing .psd1
files and also discusses alternative data formats, including JSON, which is also worth considering.
Example:
The PowerShell equivalent of the following Groovy config file (taken from the docs):
grails.webflow.stateless = true
smtp {
mail.host = 'smtp.myisp.com'
mail.auth.user = 'server'
}
resources.URL = 'http://localhost:80/resources'
is:
@{
grails = @{ webflow = @{ stateless = $true } }
smtp = @{
mail = @{
host = 'smtp.myisp.com'
auth = @{ user = 'server' }
}
}
resources = @{ URL = 'http://localhost:80/resources' }
}
As you can see, there are similarities in syntax, but PowerShell's is invariably more verbose, primarily because it doesn't support implicit nesting of the hasthables (maps, in Groovy terms).
Parsing the above with Import-PowerShellDataFile
results in a single, nested hashtable whose top-level keys as grails
, smtp
, and resources
- but not the the order of the entries is not guaranteed to match the order in the input file.