我正在尝试导入一个包含多个AD组的.csv文件,我只想获得注释和描述字段。我目前有一些错误,我不确定我做错了什么。任何帮助都将不胜感激。
$ADGroups = import-csv "C:UsersUserDocumentsADNotesField.csv"
foreach ($ADGroup in $ADGroups)
{ Get-ADGroup -Identity $ADGroup -Properties info, description
}
$ADGroup | Export-CSV -Path "C:UsersUserDocuments.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
如果您真的有一个CSV(逗号分隔(,并且考虑到Users
列有您需要查询的AD组,那么以下操作应该有效:
Import-Csv "C:UsersUserDocumentsADNotesField.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:UsersUserDocuments.csv" -NoTypeInformation