I am trying to write a script that will import a csv file and update a set of custom attributes that were built into our AD Schema.
Here is the basic code:
Import-Module ActiveDirectory
$USERS = Import-Csv c:\temp\test2.csv
foreach ($user in $users) {
Get-ADComputer -filter {dnsname -eq $user.ComputerName} |
Set-ADComputer -replace @{bSBPrimaryUser = $user.bSBPrimaryUser}
}
Here is my Error Message:
Set-ADComputer : Cannot bind parameter 'Replace' to the target. Exception setting "Replace": "Object reference not set to an instance of an object." At C:\Users\nwatson\Documents\Update Computers.ps1:7 char:24
Set-ADComputer -replace <<<< @{bSBPrimaryUser = $user.bSBPrimaryUser}}
CategoryInfo : WriteError: (:) [Set-ADComputer], ParameterBindingException
FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.ActiveDirectory.Management.Commands.SetADComputer
For some reason if I write a basic command like below it works, but not in the array.
Set-ADComputer as-001 -replace @{ bSBPrimaryUser = "Joe Smith";}