I got errors in merged scripts

  Kiến thức lập trình

Could you please tell me how to fix an error.
The error is “Cannot validate argument on parameter ‘Identity’.
The argument is null. Provide a valid value for the argument, and then try running the command again.”
Below is overall script.


  $csvpath = "xxxxx.csv"
  $parentgroups =Import-Csv -Encoding Default $csvpath

  $filepath = "xxxxxxx.csv"

  //Get users from nested group
  function ShowUser ($group){

  $dn = Get-ADGroup -Identity $group).DistinguishedName  //Error occurred in this line
  $members = Get-ADObject -LDAPFilter "(memberOf=$dn)"
  $Table = @()

  Foreach($member in $members){

  if($member.ObjectClass -eq "user"}{
  $Record = [PSCustomObject]@{
  SubSecurityGroup = $group
  UserAccount = $member.SamAccountName
  }
  $Table = $Record
  $Table | Export-Csv -Append -Path $filepath -NoTypeInformation
  }
  elseif ($member.objectClass -eq "group") {ShowUser ($member.SamAccountName)}
}
}

//Below is main component
Foreach($parentgroup in $parentgroups){
  ShowUser ($parentgroup.MailingList)
}

I ran each line of the script individually, and it didn’t throw any errors at that time.

New contributor

omoko is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT