【发布时间】:2017-07-19 18:39:29
【问题描述】:
我正在尝试将新创建的用户帐户信息通过管道传输到 csv 文件中,我想存储随机密码、显示名称和他们的电子邮件地址,如 select 语句所示,我哪里出错了?!
我的代码:
$newUserData = New-MsolUser -UserPrincipalName xxxx@xx.com -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
【问题讨论】:
-
您是否引用了这些选项的论点?我看到
-DisplayName xxxxx xxx。在单独的行中输入$newUserData会得到什么输出? -
您使用的实际值是什么来代替“文件路径”?
-
@TheIncorrigible1 如果我输入 $newUserData.Displayname,它将输出显示名称。它只是我文件的一个字符串,我向你保证它是正确的,我只是不想显示它。
-
你能给出一个示例路径吗?例如C:\Temp\csvexample.csv 看看是否有效?还可以尝试
Test-Path 'path'以确保它有效 -
文件不存在?当我找到一个不存在的文件的路径时,它创建了该文件并正确运行,然后我再次运行该命令并按预期附加,嗯。
标签: powershell csv export