about_PsdKit.help.txt

TOPIC
    about_PsdKit
 
SHORT DESCRIPTION
    PowerShell data (psd1) tool kit
 
LONG DESCRIPTION
    The module provides the following commands:
 
    - Data persistence via PowerShell data (psd1) files:
 
        - ConvertTo-Psd - Converts objects to psd1 strings.
        - Import-Psd - Imports objects from a psd1 file.
 
    - Updates of psd1 files preserving comments and structure:
 
        - Convert-PsdToXml - Converts a psd1 string to PSD-XML.
        - Convert-XmlToPsd - Converts PSD-XML to a psd1 string.
        - Export-PsdXml - Exports PSD-XML to a psd1 file.
        - Import-PsdXml - Imports a psd1 file as PSD-XML.
        - Get-Psd - Gets node PowerShell data.
        - Set-Psd - Sets node PowerShell data.
 
    PSD-XML import/export scenarios:
 
        - Expressions except values and casts are not supported.
        - New lines, comments, and separators are preserved.
        - Spaces and tabs are not necessarily preserved.
        - The order of values is preserved.
        - Supported data:
            - Table
                @{} with items separated by new lines or semicolons
            - Array
                @() with values separated by new lines or commas
            - String
                single quoted simple or verbatim strings are preserved,
                other strings are saved as single quoted simple strings
            - Number
                numbers with optional hex notation and suffixes
            - Variable
                $null, $true, $false
                other variables are supported but unusual in psd1
            - Cast
                Expressions like [DateTime] '2018-01-01'
 
EXAMPLE
    Dump object properties
 
        $Host | ConvertTo-Psd -Depth 2
 
EXAMPLE
    Write and read psd1 log file
 
        # Append log records several times
        @{time = Get-Date; text = ...} | ConvertTo-Psd | Add-Content log.psd1
 
        # Read log records
        Import-Psd log.psd1
 
EXAMPLE
    Convert JSON to psd1
 
        # some data
        $json = $Host | ConvertTo-Json -Depth 1
 
        # convert to psd1
        $json | ConvertFrom-Json | ConvertTo-Psd
 
EXAMPLE
    Change the version in a psd1 module manifest
 
        # Read psd1 as PSD-XML
        $xml = Import-PsdXml $FilePath
 
        # Set the new version
        Set-Psd $xml 1.0.2 'Data/Table/Item[@Key="ModuleVersion"]'
 
        # Save changed PSD-XML
        Export-PsdXml $FilePath $xml
 
PSD-XML SCHEMA
    With Get-Psd and Set-Psd you do not have to know much about the schema,
    they operate with native PowerShell data. But for some XPath paths,
    often simple and similar, some understanding is needed.
 
    <Data>
        The root node.
        Attributes:
            Indent: inferred non-default indent (two spaces or one tab)
                    or some custom indent used as default on exporting
        Nodes:
            Table, Array, String, Number, Variable, Cast,
            Comment, NewLine, Comma, Semicolon
    <Table>
        Hashtable nodes for `@{}`.
        Nodes:
            Item, Comment, NewLine, Semicolon
    <Item>
        Hashtable item for `key = value`.
        Attributes:
            Key: hashtable key value
            Type:
                "" ~ usual not quoted string key
                "String" ~ quoted string key
                "Number" ~ numeric key
        Nodes:
            same as <Data>
    <Array>
        Array nodes for `@()`.
        Nodes:
            same as <Data>
    <String>
        Attributes:
            Type: "1" ~ single quoted here-string
        Text:
            string value
    <Number>
        Text:
            number value
    <Variable>
        Text:
            variable name without `$`
    <Cast>
        Attributes:
            Type: type literal, e.g. `[DateTime]`
        Nodes:
            String, Number, Variable
    <Comment>
        Text:
            comment text including `#` or `<# #>`
    <NewLine>
    <Comma>
    <Semicolon>
        Empty nodes representing separators.