附加到CSV文件错误

问题描述:

我想将新创建的用户帐户信息传输到csv文件中,我想存储随机密码,显示名称和他们的电子邮件地址,如select语句所示,我去了哪里错误?!附加到CSV文件错误

我的代码:

$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" 

我的错误:

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 

的$ newUserData输出

> $newUserData 
Password UserPrincipalName      DisplayName isLicensed 
-------- -----------------      ----------- ---------- 
xxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx False 
+0

你在引用你的参数吗?我看到'-DisplayName xxxxx xxx'。你从自己的行输入'$ newUserData'会得到什么结果? – TheIncorrigible1

+1

您用来代替“PATH TO FILE”的实际值是多少? –

+0

@TheIncorrigible1如果我键入$ newUserData.Displayname,它将输出显示名称。 mat-它只是一个字符串到我的文件,我向你保证是正确的,我真的不想显示它。 – BLang

这听起来像有与对象的问题越来越发送到出口为CSV或参数本身。试试这个:

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