从导入 CSV 文件获取 AD 组注释和描述字段

发布于 2025-01-16 17:10:11 字数 1025 浏览 0 评论 0原文

我正在尝试导入包含多个 AD 组的 .csv 文件,并且我只想获取注释和说明字段。我目前遇到错误,并且不确定我做错了什么。任何帮助将不胜感激。

$ADGroups = import-csv "C:\Users\User\Documents\ADNotesField.csv"
foreach ($ADGroup in $ADGroups)
{   Get-ADGroup -Identity $ADGroup -Properties info, description
}
$ADGroup | Export-CSV -Path "C:\Users\User\Documents.csv" -NoTypeInformation

这是我收到的错误:

Get-ADGroup : Cannot convert 'System.Object[]' to the type 'Microsoft.ActiveDirectory.Management.ADGroup' required by parameter 'Identity'. Specified method is not supported.
At line:3 char:25
+ {    Get-ADGroup -identity $ADGroups -Properties info, description
+                            ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-ADGroup], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.ActiveDirectory.Management.Commands.GetADGroup

CSV 文件前几行从单元格 A1 开始,一直到 A2,等等。所有这些都是 AD 组:

Domain Users
Washington Techs
California Techs
Nevada Techs

I'm trying to import a .csv file that contains multiple AD groups and I want to get only the notes and Description field. I'm currently getting errors, and I'm not sure what I'm doing incorrectly. Any help will be appreciated.

$ADGroups = import-csv "C:\Users\User\Documents\ADNotesField.csv"
foreach ($ADGroup in $ADGroups)
{   Get-ADGroup -Identity $ADGroup -Properties info, description
}
$ADGroup | Export-CSV -Path "C:\Users\User\Documents.csv" -NoTypeInformation

This is the error that I'm receiving:

Get-ADGroup : Cannot convert 'System.Object[]' to the type 'Microsoft.ActiveDirectory.Management.ADGroup' required by parameter 'Identity'. Specified method is not supported.
At line:3 char:25
+ {    Get-ADGroup -identity $ADGroups -Properties info, description
+                            ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-ADGroup], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.ActiveDirectory.Management.Commands.GetADGroup

CSV File first few lines starting at cell A1 and going down to A2, etc. All of these are AD Groups:

Domain Users
Washington Techs
California Techs
Nevada Techs

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

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

发布评论

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

评论(1

愚人国度 2025-01-23 17:10:12

如果您确实有 CSV(逗号分隔)并且考虑到 Users 列包含您需要查询的 AD 组,则以下操作应该有效:

Import-Csv "C:\Users\User\Documents\ADNotesField.csv" | ForEach-Object {
    try {
        Get-ADGroup -Identity $_.Users -Properties info, description
    }
    catch {
        Write-Warning $_.Exception.Message
    }
} | Select-Object Name, Info, Description |
Export-CSV -Path "C:\Users\User\Documents.csv" -NoTypeInformation

If you really have a CSV (comma-delimited) and considering the Users column has the AD Groups you need to query, the following should work:

Import-Csv "C:\Users\User\Documents\ADNotesField.csv" | ForEach-Object {
    try {
        Get-ADGroup -Identity $_.Users -Properties info, description
    }
    catch {
        Write-Warning $_.Exception.Message
    }
} | Select-Object Name, Info, Description |
Export-CSV -Path "C:\Users\User\Documents.csv" -NoTypeInformation
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文