摘要
检索配置文档中资源实例的当前状态。
语法
来自 stdin 的配置文档
<document-string> | dsc config get [Options]
选项字符串中的配置文档
dsc config get [Options] --document <document-string>
文件中的配置文档
dsc config get [Options] --path <document-filepath>
说明
子 get
命令返回配置文档中资源实例的当前状态。 此命令运行时,DSC 会先验证配置文档,然后再对文档中定义的每个资源实例调用 get 操作。
配置文档必须通过 stdin 以 JSON 或 YAML 的形式传递到此命令,作为包含 document 选项的字符串,或者从具有 path 选项的文件中传递。
示例
示例 1 - 获取配置的资源实例的当前状态
命令返回在保存 example.dsc.config.yaml
为 的配置文档中定义的资源实例的实际状态。
# example.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Windows only
type: Microsoft.DSC/Assertion
properties:
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: os
type: Microsoft/OSInfo
properties:
family: Windows
- name: Current user registry example
type: Microsoft.Windows/Registry
properties:
keyPath: HKCU\example
_exist: true
dependsOn:
- "[resourceId('Microsoft.DSC/Assertion', 'Windows only')"
cat ./example.dsc.config.yaml | dsc config get
示例 2 - 传递要读取的文件作为配置文档
命令使用 path 选项检索文件中 example.dsc.config.yaml
定义的资源实例。
dsc config get --path ./example.dsc.config.yaml
示例 3 - 将配置文档作为变量传递
命令使用 document 选项检索存储在 $desired
变量中的配置文档中定义的资源实例。
dsc config get --document $desired
选项
-d, --document
指定要检索其实际状态的配置文档。 文档必须是包含 JSON 或 YAML 对象的字符串。 DSC 根据配置文档架构验证文档。 如果验证失败,DSC 将引发错误。
此选项不能与 stdin 或 --path
选项上的配置文档一起使用。 选择是将配置文档通过 stdin 传递到命令,还是从具有 --path
选项 --document
的 文件中传递。
Type: String
Mandatory: false
-p、 --path
定义配置文档的路径,以便检索其实际状态,而不是从 stdin 管道传递文档,或者使用 选项将其作为字符串 --document
传递。 指定的文件必须包含 JSON 或 YAML 对象的配置文档。 DSC 根据配置文档架构验证文档。 如果验证失败,或者指定的文件不存在,DSC 将引发错误。
此选项与 --document
选项互斥。 使用此选项时,DSC 会忽略来自 stdin 的任何输入。
Type: String
Mandatory: false
-f, --format
选项 --format
控制命令的控制台输出格式。 如果将命令输出重定向或捕获为变量,则输出始终为 JSON。
Type: String
Mandatory: false
DefaultValue: yaml
ValidValues: [json, pretty-json, yaml]
-h、--help
显示当前命令或子命令的帮助。 指定此选项时,应用程序将忽略此选项之后的所有选项和参数。
Type: Boolean
Mandatory: false
输出
此命令返回 JSON 输出,其中包括操作或任何资源是否引发任何错误、操作期间发出的消息集合以及每个实例的获取操作结果。 有关详细信息,请参阅 dsc config get result schema。