about_PsdKit.help.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
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 - Block script block, 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 XPath paths, often simple and similar, need some understanding. <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, Block, 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 `$` <Block> Text: script block content 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. |