Home > Net >  Get AD Groups Notes and Description Field From Importing CSV File
Get AD Groups Notes and Description Field From Importing CSV File

Time:03-25

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

CodePudding user response:

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\Michael.Sippy\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\Michael.Sippy\Documents.csv" -NoTypeInformation
  • Related