none
why would this script give off an error? RRS feed

  • Question

  • i have this simple script to update user's phone extension using their samAccountName as the search key. it does the job but it also gives off  the error below for no apparent reason (to me):

    Import-CSV 'd:\newphone.csv' | foreach-object {
        Set-ADuser -Identity $_.ID -Replace @{ipPhone=$_.extension; msExchExtensionAttribute16=$_.extension}
    }

    here is the error:

    Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
    At C:\Users\x\OneDrive\scripts\addPhone.ps1:2 char:18
    +   if (Get-ADuser $_.ID) {
    +                  ~~~~~
        + CategoryInfo          : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser

    am i missing something?

    Regards,

    Rino


    • Edited by Reno Mardo Thursday, June 9, 2016 6:36 AM
    Thursday, June 9, 2016 6:35 AM

Answers

  • Hi Reno,

    any single value in the Csv might be invalid (by being empty). For example, your Csv might contain an empty trailing line.

    Best check the file with a text editor (e.g.: Notepad++) for the actual content. In Excel this can be easier to miss.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Reno Mardo Thursday, June 9, 2016 8:57 AM
    Thursday, June 9, 2016 7:38 AM

All replies

  • ID in the CSV file does not contain a valid value.


    \_(ツ)_/

    Thursday, June 9, 2016 6:52 AM
  • Hi Reno,

    any single value in the Csv might be invalid (by being empty). For example, your Csv might contain an empty trailing line.

    Best check the file with a text editor (e.g.: Notepad++) for the actual content. In Excel this can be easier to miss.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Reno Mardo Thursday, June 9, 2016 8:57 AM
    Thursday, June 9, 2016 7:38 AM
  • oh yeah. there's an extra line and another line with a single comma on it.

    thanks!

    Thursday, June 9, 2016 8:57 AM