ConvertToStringData by Chad Miller 34 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1986"></script>download | new post
Converts a hashtable to a string representation of the hashtable definition. Useful in persisting hashtables to .NET Isolated Storage
- function ConvertTo-StringData
- {
- Begin
- {
- $string = "@{`n"
- function Expand-Value
- {
- param($value)
- if ($value -ne $null) {
- switch ($value.GetType().Name)
- {
- 'String' { "`"$value`"" }
- 'Boolean' { "`$$value" }
- default { $value }
- }
- }
- else
- { "`$null" }
- }
- }
- Process
- {
- $string += $_.GetEnumerator() | foreach {"{0} = {1}`n" -f $_.Name,(Expand-Value $_.Value)}
- }
- End
- {
- $string += "}"
- Write-Output $string
- }
- } #ConvertTo-StringData
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository