Dela via


resourceId

Synopsis

Returnerar den unika identifieraren för en resurs.

Syntax

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

Description

Funktionen resourceId() returnerar en referens till en specifik resursinstans i konfigurationen. Med den här funktionen kan instanser referera till en annan instans för alternativet dependsOn .

Anteckning

När du använder resourceId funktionen för kapslade resursinstanser kan instanser endast referera till andra instanser i samma resursprovider eller gruppinstans. De kan inte använda resourceId() funktionen för att söka efter instanser på den översta nivån i konfigurationsdokumentet eller inuti en annan provider eller gruppinstans.

Exempel

Exempel 1 – Referera till en resurs som ett beroende

Följande konfiguration använder resourceId() funktionen för att referera till instansen med namnet Tailspin Key som ett beroende för resursinstansen 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')]"

Exempel 2 – Referera till en gruppresurs som ett beroende

Följande konfiguration använder resourceId() funktionen för att ange resursinstansen DSC/AssertionGroup med namnet IsWindows som ett beroende för resursinstansen 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

Parametrar

resourceTypeName

Värdet för typegenskapen för resursinstansen som ska refereras. Värdet måste vara det fullständigt kvalificerade typnamnet för resursen.

Type:     string
Required: true
Position: 0

instanceName

Värdet för namnegenskapen för resursinstansen som ska refereras.

Type:     string
Required: true
Position: 0