通过设备ID进行Get-azureaddevice过滤

发布于 2025-02-02 17:38:21 字数 440 浏览 4 评论 0原文

我有一个Azure DeviceID的列表,并希望使用PowerShell命令删除-AsureadDevice删除它们,但是我只能通过设备的objectID删除它们。 因此,我现在的问题是我将匹配的objectid降低到deviceids的位置? 我只是得到这个错误消息

$csv = Import-Csv "C:\powershell\restazure.csv"

foreach($item in $csv){
    $removeThisDevices = Get-AzureAdDevice -Filter "deviceId eq $item.ID"
    }

消息:语法错误:字符'{'在位置13中无效 'DeviceID EQ @{ID = 445925F3-C35B-40AF-B5D4-1F71DEE08A39} .id'。

I have a list of Azure DeviceIDs and want to delete them with the Powershell command Remove-AzureADDevice, but i can only delete them by the ObjectID of a device.
so my question now is where i get the matching objectIDs to the DeviceIDs?
I'm just getting this Error-Message

$csv = Import-Csv "C:\powershell\restazure.csv"

foreach($item in $csv){
    $removeThisDevices = Get-AzureAdDevice -Filter "deviceId eq $item.ID"
    }

Message: Syntax error: character '{' is not valid at position 13 in
'deviceId eq @{ID=445925f3-c35b-40af-b5d4-1f71dee08a39}.ID'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

止于盛夏 2025-02-09 17:38:21

昨天这让我发疯。如果您查看错误,它将抱怨类型不匹配。 DeviceID是GUID。

我没有运气使用GUID键入变量:

$guid = [GUID]$deviceId
Get-AzureAdDevice -Filter "deviceId eq $($guid)"

这项工作:

#In my case it was an AD object
$deviceId = $adcomp.objectGuid
Get-AzureAdDevice -Filter "deviceId eq guid'$($deviceID)'" #<--yes, you need the single quotes.

感谢Github上的Klikr发布解决方案和链接以帮助文件,这似乎阐明了很多事情: https://github.com/azure/azure/azure-docs-powershell-azuread/shell-azuread/isshell-azuread/issues/issues/216#issuecomment-63333322 < /a>

帮助文件: https://www.powershellgallery.com/packages/azureadpreview/2.0.0.52/content/content/it%5cmicrosoft.azuread.azuread16.graph.graph.powershell.powershell.dll-hell.dll-hellp.xmll

ninl klikrikr: -p,我将在本周末阅读一些ODATA文档,以便我更好地理解所有这些文档。我发现自己写更多的自动化,需要Azure Err Entra数据,因此,如果我只知道并且不必搜索和玩耍就可以弄清楚某些事情,那就太好了。很棒的是他们具有铸造功能。

This was driving me crazy yesterday. If you look at the error it will complain about the type mismatch. DeviceID is a GUID.

I had no luck using a GUID typed variable:

$guid = [GUID]$deviceId
Get-AzureAdDevice -Filter "deviceId eq $($guid)"

This works:

#In my case it was an AD object
$deviceId = $adcomp.objectGuid
Get-AzureAdDevice -Filter "deviceId eq guid'$($deviceID)'" #<--yes, you need the single quotes.

Thank klikr on GitHub for posting the solution and link to help file which seems to spell out quite a few things: https://github.com/Azure/azure-docs-powershell-azuread/issues/216#issuecomment-633943632

Help file: https://www.powershellgallery.com/packages/AzureADPreview/2.0.0.52/Content/it%5CMicrosoft.Open.AzureAD16.Graph.PowerShell.dll-Help.xml

Unlike klikr :-P, I'll be reading some OData documentation this weekend so I can better understand all this. I'm finding myself writing more automation which requires Azure err Entra data, so it'd be nice if I just knew and didn't have to search and play around to figure certain things out. Great that they have casting functionality though.

毁梦 2025-02-09 17:38:21

请尝试

$alldevices = Get-AzureADDevice -All:$true

$ids = "aea06b1b-5413-49fb-9529-372cabb8bfa0",
"642734b1-d804-4043-94e6-ce6508b5ca5b",
"afd5bf18-752b-4b54-84f5-56426dd9b716",
"5d0b7ae6-c600-41e5-90d8-4bac58f21463",
"4f2f91e0-0b06-45c4-a04c-067620c81359",
"cab6a732-dc97-4209-bc05-87353d6dbeab",
"1e8b4deb-e7f1-4e0c-be7d-0a2219fffeb2"

$alldevices | ? {$_.DeviceId -in $ids}
ObjectId                             DeviceId                             DisplayName
--------                             --------                             -----------
0af944f0-bdf5-48c8-828d-c966b7b4f48c 5d0b7ae6-c600-41e5-90d8-4bac58f21463 H170HmNP0
115f4236-bb15-4400-8d2a-25788216476b afd5bf18-752b-4b54-84f5-56426dd9b716 Ø967BEN
3fc6c791-f42e-4d1e-a5b5-662d2904e41a 642734b1-d804-4043-94e6-ce6508b5ca5b Ø967
541afa98-0664-4346-861a-456514f7f90c 4f2f91e0-0b06-45c4-a04c-067620c81359 Ø967BN
8d01df67-856d-4c19-8252-71dbe4b10263 aea06b1b-5413-49fb-9529-372cabb8bfa0 Ø967Bwhuw
d5fbf819-4879-4c8d-97c8-8379d56316ff 1e8b4deb-e7f1-4e0c-be7d-0a2219fffeb2 Ø967BIsCCk
d6ce3aef-4d12-4584-907c-6ded1630f6ec cab6a732-dc97-4209-bc05-87353d6dbeab Ø967BWbOm
f650da66-e978-42f9-9206-ad32be413769 435ae308-601f-4784-aff8-6f3ca2adc827 Ø967BrBg

Please try this

$alldevices = Get-AzureADDevice -All:$true

$ids = "aea06b1b-5413-49fb-9529-372cabb8bfa0",
"642734b1-d804-4043-94e6-ce6508b5ca5b",
"afd5bf18-752b-4b54-84f5-56426dd9b716",
"5d0b7ae6-c600-41e5-90d8-4bac58f21463",
"4f2f91e0-0b06-45c4-a04c-067620c81359",
"cab6a732-dc97-4209-bc05-87353d6dbeab",
"1e8b4deb-e7f1-4e0c-be7d-0a2219fffeb2"

$alldevices | ? {$_.DeviceId -in $ids}
ObjectId                             DeviceId                             DisplayName
--------                             --------                             -----------
0af944f0-bdf5-48c8-828d-c966b7b4f48c 5d0b7ae6-c600-41e5-90d8-4bac58f21463 H170HmNP0
115f4236-bb15-4400-8d2a-25788216476b afd5bf18-752b-4b54-84f5-56426dd9b716 Ø967BEN
3fc6c791-f42e-4d1e-a5b5-662d2904e41a 642734b1-d804-4043-94e6-ce6508b5ca5b Ø967
541afa98-0664-4346-861a-456514f7f90c 4f2f91e0-0b06-45c4-a04c-067620c81359 Ø967BN
8d01df67-856d-4c19-8252-71dbe4b10263 aea06b1b-5413-49fb-9529-372cabb8bfa0 Ø967Bwhuw
d5fbf819-4879-4c8d-97c8-8379d56316ff 1e8b4deb-e7f1-4e0c-be7d-0a2219fffeb2 Ø967BIsCCk
d6ce3aef-4d12-4584-907c-6ded1630f6ec cab6a732-dc97-4209-bc05-87353d6dbeab Ø967BWbOm
f650da66-e978-42f9-9206-ad32be413769 435ae308-601f-4784-aff8-6f3ca2adc827 Ø967BrBg
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文