How do I get this to use the Set-ADUser -Replace @params
I get this error message as DepartmentNumber is not a normal property, and in my last script i had to use the set-aduser -replace
Otherwise is looks like this script is actually doing the goal of updating AD properties from the spreadsheet and it doesnt care i have blank fields .
here is my headers
City postalcode OfficePhone DepartmentNumber
Rockford 61008 222-222-5555 D2255
Set-ADUser : A parameter cannot be found that matches parameter name 'DepartmentNumber'.
At C:\Users\gdrews\desktop\Update-ADattributes\adup5.ps1:18 char:15
+ Set-ADUser <<<< @params
+ CategoryInfo : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser
$properties = @(
'city',
'postalcode',
'OfficePhone'
'DepartmentNumber'
)
Import-Csv c:\temp\users.csv |
ForEach-Object {
$params = @{}
foreach ($property in $properties)
{
if ($_.$property)
{ $params.$property = $_.$property }
}
get-ADUser -LDAPFilter "(samaccountname=$($_.samaccountname))" |
Set-ADUser @params
}