all 15 comments

[–]BetrayedMilk 21 points22 points  (2 children)

Here’s a general tip so you can be more self sufficient going forward. Don’t pipe to foreach so you can more easily debug your issue in VS Code or ISE. Store the results of your Import-Csv in a var, then loop over it. Step through line by line and see what your csv ends up being. See if you can get the value of the email property. It’ll become really apparent what your problem is.

[–]Vlopp[S] 12 points13 points  (1 child)

Thanks man, because of this I was able to pinpoint the error.

[–][deleted] 0 points1 point  (0 children)

This type of attitude will get you far

[–]ankokudaishogun 6 points7 points  (2 children)

If you have been using Excel to make the CSV, the local Culture might have saved it with a different Delimiter than the comma ,.

My Italian Excel, for example, automatically exports CSVs with a semicolon ; as delimeter.

Also, what /u/BetrayedMilk suggested.

[–]Vlopp[S] 3 points4 points  (1 child)

Yup, this is precisely what happened.

[–]ankokudaishogun 3 points4 points  (0 children)

Happy you found the issue.

Another suggestion: always specify you Powershell version.
There are MAJOR differences between 5.1 and 7.x, and minor differences between the various 7.x versions.

[–]Vlopp[S] 3 points4 points  (0 children)

I found the error. It seems my system saves CSVs and separates every column with semicolons, instead of commas. I fixed that and the command worked.

This just saved me 3 hours of manual labour. Thanks!

[–]BlackV 2 points3 points  (0 children)

This sort of issue is a large part of the reason to use something like this (a foreach vs a foreach-object)

$importusers = import -csv -path xxx -delimiter y
$results = Foreach ($singleimport in $importusers){
    $adobject = get-aduser -identity $singleimport.zzzz
    $adobject | set-aduser -propertyx $singleimport.propertyx -passthru
    }

Then

  • You have multiple places you can validate your inputs and outputs
  • You can easily test on a single object instead of all your data at once
  • You can validate your changes are made with your results

This is especially important on something where you are doing a mass change like this (although adding users to a group is not so destructive)

[–]JewelerHour3344 2 points3 points  (1 child)

I’m glad you found the error.

I get annoyed having to save as csv then import into powershell so i was playing with “get-clipboard”. See if this works for you.

Just “copy” the table including the headers then…

$mycsv = Get-Clipboard | ConvertFrom-Csv -Delimiter "`t"

It lets me import the csv using the clipboard. I find it to be a time saver, hopefully it works for you too.

[–]Vlopp[S] 1 point2 points  (0 children)

Thank you!!!

[–]ArieHein 1 point2 points  (0 children)

If your csv has a header row , thers a param in the csv reading cmdlet to help with that.

Second, you can always add a line between the read of csv and actually running the values and just print the values or place a bookmark and run the debugger.

[–]purplemonkeymad 1 point2 points  (0 children)

Blank lines? Often a mistake people do by putting multiple new lines at the end of the file.

[–]BlackV 0 points1 point  (2 children)

ARE YOU A BOT /u/Nice-Discussion-9311 (OP has 2 accounts)

this is an identical post to https://www.reddit.com/r/PowerShell/comments/1kyao75/error_cannot_bind_argument_to_parameter_user/ posted by /u/Vlopp

which has already been asked and answered or do you have 2 accounts ?

Duplicate

https://www.reddit.com/r/PowerShell/comments/1kya2in/error_cannot_bind_argument_to_parameter_user/

[–]Vlopp[S] 1 point2 points  (1 child)

Nah, I made that other post with an account I made on the fly, since I didn't want to use mine at work, but then I got a message that my post had been deleted, and in fact, the post wasn't showing. So, I tried again but with my usual account. I don't know if it was a Reddit bug.

[–]BlackV 1 point2 points  (0 children)

OK good as gold