base64

摘要

返回输入字符串的 base64 表示形式。

语法

base64(<inputString>)

说明

函数 base64() 返回输入字符串的 base64 表示形式。 传递编码为 base64 的数据可以减少传递数据时出现的错误,尤其是在不同的工具需要不同的转义字符时。

示例

示例 1 - 将字符串转换为 base64

配置使用 base64() 函数转换基本字符串值。

# base64.example.1.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
  - name: Echo 'abc' in base64
    type: Test/Echo
    properties:
      output: "[base64('abc')]"
dsc --input-file base64.example.1.dsc.config.yaml config get
results:
- name: Echo 'abc' in base64
  type: Test/Echo
  result:
    actualState:
      output: YWJj
messages: []
hadErrors: false

示例 2 - 将串联字符串转换为 base64

配置使用 函数内的 base64()concat () 函数将字符串 abc 合并到 中abc,然后再返回 base64 表示形式。

# base64.example.2.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
  - name: Echo concatenated 'a', 'b', 'c' in base64
    type: Test/Echo
    properties:
      output: "[base64(concat('a', 'b', 'c'))]"
dsc --input-file base64.example.2.dsc.config.yaml config get
results:
- name: Echo concatenated 'a', 'b', 'c' in base64
  type: Test/Echo
  result:
    actualState:
      output: YWJj
messages: []
hadErrors: false

参数

inputString

函数 base64() 需要单个字符串作为输入。 函数将值转换为 base64 表示形式。 如果值不是字符串,则 DSC 在验证配置文档时会引发错误。

Type:         string
Required:     true
MinimumCount: 1
MaximumCount: 1

输出

函数 base64() 返回 inputString 值的 base64 表示形式。

Type: string