在DevOps管道中运行PowerShell脚本
我使用以下PS脚本(简化版本,但此处发生错误)来识别已过期的AppRegistrations:
$allapps = az ad app list --all | ConvertFrom-Json
$allapps | ForEach-Object {
$app = $_
@(
$EndDate = az ad app credential list --id $_.objectId | ConvertFrom-Json
$EndDate.endDate
)
}
当我以VS代码本地对其进行测试时,它可以正常工作。
在VSCODE中的输出:
2022-01-25T11:51:11.205912+00:00
2024-02-21T12:52:11.542000+00:00
2023-06-17T11:54:30.328000+00:00
...
但是,我的目标是将此脚本集成到Azure DevOps管道中。要在DevOps中运行脚本,我使用DevOps 任务:Azurecli@2 并使用服务连接登录。
当我在DevOps管道中运行它时,我会收到以下错误:
ERROR: argument --id: expected one argument
Examples from AI knowledge base:
az ad app credential list --id 00000000-0000-0000-0000-000000000000
list an application's password or certificate credentials (autogenerated)
看起来 AZ AD App凭据列表没有获得 -ID 的输入。
当我在VSCODE再次运行相同的代码时,但是没有 convertfrom-json 时,我会遇到相同的错误。因此,我怀疑这是因为 convertfrom-json 不起作用。
你们有什么想法是什么造成了这一点,以及如何解决问题?
I use the following PS script (simplified version, but the error happens here) to identify expired AppRegistrations:
$allapps = az ad app list --all | ConvertFrom-Json
$allapps | ForEach-Object {
$app = $_
@(
$EndDate = az ad app credential list --id $_.objectId | ConvertFrom-Json
$EndDate.endDate
)
}
When I test it locally in VS code, it works fine.
Output in VSCode:
2022-01-25T11:51:11.205912+00:00
2024-02-21T12:52:11.542000+00:00
2023-06-17T11:54:30.328000+00:00
...
However, my goal is to integrate this script into Azure Devops pipelines. To run script in devops I use the devops task: AzureCLI@2
And do login with Service Connection.
When I run it in devops pipelines, I get the following error:
ERROR: argument --id: expected one argument
Examples from AI knowledge base:
az ad app credential list --id 00000000-0000-0000-0000-000000000000
list an application's password or certificate credentials (autogenerated)
It looks like az ad app credential list is not getting input for --id.
When I run the same code again in VSCode but without ConvertFrom-Json I get the same error. Therefore I suspect that it is because ConvertFrom-Json is not working.
Do you guys have any ideas what is causing this and how I can solve the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我测试了PowerShell脚本,并遇到了同样的问题。
此问题的原因是,在Azure CLI的响应中,它没有名为Objectid的字段。
预期的obsectedId名称是ID。
因此,您需要将
$_。.Objectid
$_。ID
修改。同时,应将$ enddate.enddate
修改为$ enddate.enddateTime
。这是一个例子:
I tested the PowerShell script and got the same issue.
The cause of this issue is that in the response of the Azure CLI, it has no field named objectId.
The expected objectedId name is ID.
So you need to modify the
$_.objectId
to$_.Id
. At the same time,$EndDate.endDate
should be modified to$EndDate.endDateTime
.Here is the example: