ResourceId

摘要

返回资源的唯一标识符。

语法

resourceId('<resourceTypeName>', '<instanceName>')

说明

函数 resourceId() 返回配置中特定资源实例的句柄。 此函数使实例能够引用 dependsOn 选项的另一个实例。

注意

resourceId将 函数用于嵌套资源实例时,实例只能引用同一资源提供程序或组实例中的其他实例。 他们不能使用 resourceId() 函数在配置文档的顶层或在另一个提供程序或组实例内查找实例。

示例

示例 1 - 引用资源作为依赖项

以下配置使用 resourceId() 函数引用名为 Tailspin Key 的实例作为资源实例的 Update Tailspin Automatically 依赖项。

# resourceId.example.1.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
  - name: Tailspin Key
    type: Microsoft.Windows/Registry
    properties:
      keyPath: HKCU\tailspin
      _ensure: Present
  - name: Update Tailspin Automatically
    type: Microsoft.Windows/Registry
    properties:
      keyPath:   HKCU\tailspin\updates
      valueName: automatic
      valueData:
        String: enable
    dependsOn:
      - "[resourceId('Microsoft.Windows/Registry', 'Tailspin Key')]"

示例 2 - 引用组资源作为依赖项

以下配置使用 resourceId() 函数将名为“IsWindows”的资源实例指定 DSC/AssertionGroup 为资源实例的 Example Key 依赖项。

# resourceId.example.2.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
  - name: IsWindows
    type: DSC/AssertionGroup
    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: Example Key
    type: Microsoft.Windows/Registry
    properties:
      keyPath: HKCU\example
      _exist: true

参数

resourceTypeName

要引用的资源实例 的类型 属性的值。 该值必须是资源的 完全限定类型名称

Type:     string
Required: true
Position: 0

INSTANCENAME

要引用的资源实例 的 name 属性的值。

Type:     string
Required: true
Position: 0