Reputation: 990
I am trying to pipe a newly created user account info into a csv file, i want to store the random password, display name, and their email address as shown by the select statement, where did i go wrong?!
My Code:
$newUserData = New-MsolUser -UserPrincipalName [email protected] -DisplayName xxxxx xxx -FirstName xxx -LastName xxxx
$newUserData | select password, displayname, userprincipalname | Export-Csv -Append -Force -Path "PATH TO FILE"
My Error:
Export-Csv : Cannot process argument because the value of argument "name" is not valid. Change the value of the "name" argument and run
the operation again.
At line:1 char:66
+ ... cipalname | Export-Csv -Append -Force -Path "PATH TO FILE" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], PSArgumentException
+ FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.ExportCsvCommand
the $newUserData output
> $newUserData
Password UserPrincipalName DisplayName isLicensed
-------- ----------------- ----------- ----------
xxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx False
Upvotes: 0
Views: 1082
Reputation: 19684
It sounds like there's an issue with the object getting sent to export-csv or the arguments themselves. Try this:
New-Item -ItemType Directory -Path C:\Temp
$newUserData = New-MsolUser -UserPrincipalName [email protected] -DisplayName User -FirstName User -LastName Test
$newUserData | Select-Object -ExcludeProperty 'isLicensed' | Export-Csv -Path C:\Temp\UserDat.csv -Append -Force
Upvotes: 1