none
is NULL the same as blank? RRS feed

Answers

  • Hi Reno,

    it's very possible to dynamically choose which properties to replace. Here an example:

    $hash = @{
    	givenName = $_.fname
    	sn = $_.lname
    	company = $_.comp
    	title = $_.title
    	department = $_.func
    	physicalDeliveryOfficeName = $_.dept
    }
    
    if ($_.address) { $hash["msExchExtensionAttribute1"] = $_.address }
    if ($_.city) { $hash["msExchExtensionAttribute2"] = $_.city }
    if ($_.zip) { $hash["msExchExtensionAttribute4"] = $_.zip }
    if ($_.phone) { $hash["msExchExtensionAttribute5"] = $_.phone }
    if ($_.loc) { $hash["msExchExtensionAttribute3"] = $_.loc }
    
    Set-ADuser -Identity $_.ID -Replace $hash

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Reno Mardo Thursday, December 1, 2016 5:44 AM
    Wednesday, November 30, 2016 11:25 AM

All replies

  • they're not :-)

    PS C:\Users\x> $a=[char]32
    
    PS C:\Users\x> $b=[char]00
    
    PS C:\Users\x> $a -eq $b
    False

    Wednesday, November 30, 2016 10:02 AM
  • Set-ADUser : Cannot validate argument on parameter 'Replace'. The argument is null or an element of the argument collection contains a null value.

    i assigned a space but got the same error.

    Wednesday, November 30, 2016 10:29 AM
  • right. so i'm stuck.

    all of what i've seen involves skipping CSV rows that contain blanks. but in my case, i don't want to skip those rows because there are other columns of the CSV that needs to be processed.

    for example, a row containing user name, address, phone might not contain phone numbers (hence blank field) for everyone but still  i need to process those users. not skip those rows.

    just can't wrap my head around it..

    Wednesday, November 30, 2016 11:00 AM
  • Hi Reno,

    it's very possible to dynamically choose which properties to replace. Here an example:

    $hash = @{
    	givenName = $_.fname
    	sn = $_.lname
    	company = $_.comp
    	title = $_.title
    	department = $_.func
    	physicalDeliveryOfficeName = $_.dept
    }
    
    if ($_.address) { $hash["msExchExtensionAttribute1"] = $_.address }
    if ($_.city) { $hash["msExchExtensionAttribute2"] = $_.city }
    if ($_.zip) { $hash["msExchExtensionAttribute4"] = $_.zip }
    if ($_.phone) { $hash["msExchExtensionAttribute5"] = $_.phone }
    if ($_.loc) { $hash["msExchExtensionAttribute3"] = $_.loc }
    
    Set-ADuser -Identity $_.ID -Replace $hash

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Reno Mardo Thursday, December 1, 2016 5:44 AM
    Wednesday, November 30, 2016 11:25 AM
  • You need to always assure that your script does not attempt to assign a null/blank value to any attribute, as this will raise errors. Also, when I update users in bulk I like to check if the new value in the CSV is different from the existing. This requires a bit more code, but allows you to reuse the CSV (perhaps exported from a spreadsheet) to update a few values, without unnecessary updates and replication traffic.

    Also, if the CSV value has blanks, you might intend for any existing value to be removed. In this case you can use another hash table, similar to $hash in Fred's example, that you pass to the -Clear parameter of Set-ADUser. Or, you might standardize on a specific string in you CSV that means to clear the attribute. I used to use the string "<delete>".


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Wednesday, November 30, 2016 1:50 PM
    Moderator
  • i'm not that familiar with that structure. so i tried with a single row containing a blank column. gave me the below error:

    Set-ADuser : replace
    At C:\Users\user\OneDrive\update4fields.-ver3.ps1:18 char:1
    + Set-ADuser -Identity $_.ID -Replace $hash
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (user:ADUser) [Set-ADUser], ADInvalidOperationException
        + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.SetADUser


    Correction: there was a typo :-) it is working perfectly.
    • Edited by Reno Mardo Thursday, December 1, 2016 5:44 AM
    Thursday, December 1, 2016 5:24 AM
  • thanks for the tip. will look into that.
    Thursday, December 1, 2016 5:25 AM