Azure Devops 使用 Powershell 从特定组织中删除特定用户

Posted

技术标签:

【中文标题】Azure Devops 使用 Powershell 从特定组织中删除特定用户【英文标题】:Azure Devops remove specific user from specific organization using Powershell 【发布时间】:2022-01-11 08:05:36 【问题描述】:

例如,我想从 Azure 开发组织 BigZoo 中移除 Tiger(Tiger 有 3 个 Azure 组织,BigZoo、SmallZoo、middleZoo——我只想从 BigZoo 中移除 Tiger)

在 Azure Cloudshell Powershell 中使用此 Azure CLI 即可运行

az devops user remove --user tiger
                      [--org BigZoo]
                      [--yes]

但在 Azure 函数中不起作用-->Azure 函数使用 PowerShell 环境--> CloudPowerShell 可以读取 AzureCLi 但 AzureFunction 中的 Powershell 无法读取与 Az 相关的任何内容

所以,如果我只想在没有 Azure CLI 帮助的情况下使用 powershell,则有一些模块,但所有导入的模块都是从所有组织中删除用户--> 不从特定组织中删除用户

有什么建议吗?从特定 AzureDevops 组织中删除用户。使用 API 似乎太复杂了。有什么好主意吗? 谢谢

【问题讨论】:

【参考方案1】:

我没有尝试过,但是 PowerShell 库中有一个 VSTteam powershell 模块,它封装了 Azure Devops API。

这有一个函数叫做:Remove-VSTeamUserEntitlement

这里的文档: https://methodsandpractices.github.io/vsteam-docs/docs/modules/vsteam/commands/Remove-VSTeamUserEntitlement

这里的模块: https://www.powershellgallery.com/packages/VSTeam/

将模块添加到您的 azure 函数项目的 Requirements.psd1 文件中,您应该可以使用它。

【讨论】:

我对你的答案投了赞成票,因为它有帮助,但实际上它不是真正的答案。这个我很久以前就知道了,但是这个 Remove-VsTeamUserEntitlement 的弱点是我们没有组织参数.....就像 Cat 有 3 个组织..如果我使用这个,这个怎么知道哪个要删除的组织可能会删除所有组织谢谢 您可以设置正在使用的帐户的上下文:methodsandpractices.github.io/vsteam-docs/docs/modules/vsteam/…,并且可以为每个接受 POST 请求并加载不同身份的组织设置不同的端点,以免混淆 Azure DevOps 组织起来。

以上是关于Azure Devops 使用 Powershell 从特定组织中删除特定用户的主要内容,如果未能解决你的问题,请参考以下文章

Azure Databricks 的 Azure DevOps 管道

azure-devops-extension-sdk:小部件的配置

使用 Azure Devops 任务或 PowerShell 创建/更新 Azure WebApp 的路径映射

Yaml Azure Devops TerraformInstaller 不明确

如何在 Azure DevOps 变量组中使用 SecureFile?

DevOps 和 Azure 应用服务中的环境变量