【发布时间】:2020-11-10 12:54:49
【问题描述】:
我有一个用于与 Microsoft GraphAPI 交互的脚本。在脚本中,我为要使用的 URL 定义了一个变量,例如
$UriGet = "https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies?`$filter=startswith(displayName,`'$Identifier`')"
然后该函数从 CSV 读取数据,并根据 $UriGet URI 处理 CSV 中的每一行。函数调用如下:
Invoke-GraphApi -UriGet $UriGet
但是,在函数内部,实际的 "$Identifier" 变量被替换为任何内容,例如就像 $UriGet 已通过评估函数前变量传递,此时它的 $null。
例如,在“Invoke-GraphApi 函数中,写入主机 $UriGet 提供
URIGet value: "https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies?$filter=startswith(displayName,'')"
所以问题是,如何将完整的字符串传递给函数而不计算变量?
编辑 - 这是函数的参数块
Param (
[parameter(Mandatory=$true)]
[Hashtable]$MsGraphAuthenticationHeader,
[parameter(Mandatory=$true)]
[String]$UriGet,
[parameter(Mandatory=$true)]
[String]$UriPatch,
[parameter(Mandatory=$true)]
[String]$UriPost,
[parameter(Mandatory=$true)]
[String]$Identifier,
[parameter(Mandatory=$true)]
[String]$RequestBody
)
【问题讨论】:
-
请告诉我们
Invoke-GraphApi函数定义(或者,至少,它的param()块) -
@MathiasR.Jessen 我已将参数块添加到原始帖子中。
标签: powershell