I'm syncing up user attributes in AD with a provided CSV file. When I try to call my SyncUser function I get the following error:
SyncUser : Cannot process argument transformation on parameter 'user'. Cannot convert the "System.Object[]" value of type "System.Object[]" to type "Microsoft.ActiveDirectory.Management.ADUser".
$user.GetType() tells me the name is ADUser with a base type of ADAccount yet the error message acts as though I'm passing an object array. Powershell is still fairly new to me so maybe my function syntax is incorrect? I'm confused at this point.
$AD_Users = Get-ADUsers -SearchBase $adPath -LDAPFilter $filter
$UPNs = $AD_Users | ForEach-Object -Begin { $ht = @{} } _Process { $ht.add($_."userPrincipalname", $_) } -End { return $ht }
Import-Csv $file | ForEach-Object {
$user = $UPNs[$_."userPrincipalName"]
SyncUser($user, $_)
}
function SyncUser{
param([Microsoft.ActiveDirectory.Management.ADUser]$user, [System.Object]$c)
# do stuff
}