0

我使用 powershell,我想将 json 格式的变量放入 TMSL 创建角色脚本。我想将此变量放入 TablePermission 参数

json变量:

$filter=
[

    {
          "name": "DimGeography",
          "filterExpression": "DimGeography[CountryRegionCode] = \"US\" "
        }
]

TMSL 脚本:

$Query='
    {  
    "create": {  
        "parentObject": {  
        "database": "AW Internet Sales"  
        },  
        "role": {
      "name": "test_filter",
      "modelPermission": "read",
      "tablePermissions": "'+$filter+'"
    }
        }
          
    }'

这是我要参数化的脚本

{
  "createOrReplace": {
    "object": {
      "database": "AW Internet Sales",
      "role": "SalesManagerUS"
    },
    "role": {
      "name": "SalesManagerUS",
      "modelPermission": "read",
      "tablePermissions": [
        {
          "name": "DimGeography",
          "filterExpression": "DimGeography[CountryRegionCode] = \"US\" "
        }
      ]
    }
  }
}

如何将 $filter 放入 $Query 以接收上述工作脚本?

4

2 回答 2

1

您可以尝试以下代码段:

    $filter=
'[

    {
          "name": "DimGeography",
          "filterExpression": "DimGeography[CountryRegionCode] = \"US\" "
        }
]'


function populate-tsml ($filter)
{


$Query='
    {  
    "create": {  
        "parentObject": {  
        "database": "AW Internet Sales"  
        },  
        "role": {
      "name": "test_filter",
      "modelPermission": "read",
      "tablePermissions": '+$filter+'
    }
        }
          
    }'

    return $Query

    }

  $Query =   populate-tsml -filter $filter

输出 :

在此处输入图像描述

于 2021-02-24T11:44:06.480 回答
0

谢谢!不需要定义一个函数,在引号中稍作改动就足够了。以下脚本有效:

$filter=
'[

    {
          "name": "DimGeography",
          "filterExpression": "DimGeography[CountryRegionCode] = \"US\" "
        }
]'




$Query='
    {  
    "create": {  
        "parentObject": {  
        "database": "AW Internet Sales"  
        },  
        "role": {
      "name": "test_filter",
      "modelPermission": "read",
      "tablePermissions": '+$filter+'
    }
        }
          
    }'
于 2021-02-24T12:22:24.877 回答