我的任务是编写一些PowerShell脚本来自动化Azure AD租户中的一些基本操作。我已经成功添加和删除了用户和域,并且我已经通过Azure Graph API添加了新的应用程序,但是我没有幸运地删除这些应用程序。
似乎关于此的文档很少,而且我无法找到任何人这样做的例子。根据支持操作下的应用程序参考,应该可以(https://msdn.microsoft.com/library/azure/ad/graph/api/entity-and-complex-type-reference#applicationentity):
支持的操作
应用程序支持以下操作(括号中列出了HTTP方法):
创建(POST)
阅读(READ)
更新(PATCH)
删除(删除)
那么URI应该是什么样的?我找不到直接答案,但要删除用户,您可以使用:
https://graph.windows.net/myorganization/users/{user_id}[?api-version]
所以,我想尝试删除一个应用程序类似的东西:
https://graph.windows.net/company.onmicrosoft.com/applications/{application_id}?api-version=1.6
如果这是正确的,那么应用程序ID是什么?客户端ID和App ID URI对我来说最有意义,但到目前为止,这些和应用程序名称都没有对我有用。这可能是格式化问题吗?根据我的尝试,我会得到不同的错误。
申请名称:
https://graph.windows.net/company.onmicrosoft.com/applications/application4?api-version=1.6
产量
Invoke-RestMethod : {"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"Invalid object identifier 'application4'."},"values":null}}
客户端ID(此处归零):
https://graph.windows.net/company.onmicrosoft.com/applications/00000000-0000-0000-0000-000000000000?api-version=1.6
产量
Invoke-RestMethod : {"odata.error":"code":"Request_ResourceNotFound","message":{"lang":"en","value":"Resource '00000000-0000-0000-0000-000000000000' does not exist or one of its queried reference-property objects are not present."}}}
App ID URI - 不确定如何添加它。我可能需要一些编码吗?试过两种方式:
https://graph.windows.net/company.onmicrosoft.com/applications/application4.company.com?api-version=1.6
哪个收益
Invoke-RestMethod : {"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"Invalid object identifier 'application4.company.com'."},"values":null}}
和
https://graph.windows.net/company.onmicrosoft.com/applications/https://application4.company.com?api-version=1.6
我怀疑编码可能出现在哪里。目前只是产生
Invoke-RestMethod : {"odata.error":{"code":"Request_BadRequest","message"{"lang":"en","value":"Bad request. Please fix the request before retrying."}}}
知道我哪里出错了?
答案 0 :(得分:3)
您需要使用objectId。除了客户端ID之外,应用程序(如所有AAD对象)都有一个objectId。
所以网址应为:
https://graph.windows.net/company.onmicrosoft.com/applications/{application_objectId}?api-version=1.6