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

Get AD Groups Notes and Description Field From Importing CSV File

我正在尝试导入一个包含多个 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 等。所有这些都是广告组:

Domain Users
Washington Techs
California Techs
Nevada Techs

如果您确实有 CSV (comma-delimited) 并且考虑到 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