从CSV导入 [英] Import from CSV

查看:92
本文介绍了从CSV导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个用户电子邮件地址列表,并且想要使用import-csv选项,这样csv文件就拥有了所有用户的电子邮件地址,我希望为csv列表中的每个用户提供SAM帐户然后将它传递给export-csv文件。

So I have a list of users email address and want to use the import-csv option, so that csv file has all the users email addresses and I want to get there SAM Account for each user in the csv list and then pipe it to export-csv file.

这是我当前的cmd,但我使用了一些不正确的属性和操作符,所以你的帮助会很棒。

This is my current cmd but I am using some incorrect property and operator, so your help will be great.

C:\> Import-Csv c:\ jason.csv | ForEach {Get-ADUser -filter {emailaddress -eq $ _。mail}} |选择SAMAccountName | Export-Csv c:\ all.csv CSV文件中的标题名称=邮件和电子邮件地址

C:\>Import-Csv c:\jason.csv | ForEach {Get-ADUser -filter {emailaddress -eq $_.mail}} |select SAMAccountName | Export-Csv c:\all.csv the header name inside the CSV file = mail and email address

邮件

jbloggs@blah.com

mail
jbloggs@blah.com

但是我收到此错误:

Get-ADUser:属性:在类型的对象中找不到'mail':'System.Management.Automation.PSCustomObject' 。

行:1字符:46

Get-ADUser : Property: 'mail' not found in object of type: 'System.Management.Automation.PSCustomObject'.
At line:1 char:46

所以我只需要正确的属性和运算符即可完成此操作。

SO I just need the correct property and operator to complete this.

推荐答案

编辑:抱歉,看起来像我误解了你的问题。该物业只需
邮件。您收到的错误是因为它正在为您传递的当前对象寻找
邮件属性。您导入的CSV中使用的属性是什么?您可能需要互相交换
emailaddress -eq

Sorry, it looks like I misinterpreted your question. The property is simply mail. The error you are receiving is because it is looking for a mail property for the current object you piped through. What are the properties you are using in the CSV you are importing? You may need to swap emailaddress -eq


_。mail
_.mail with each other.

上一个答案:

Previous answer:

使用导入-CSV C:\ jason.csv | Foreach {Get-ADUser

Use Import-CSV C:\jason.csv | Foreach {Get-ADUser


_  -Properties mail} |选择SAMAccountName,mail |导出-CSV C:\ all.csv -NoTypeInformation
代替。



(如果您希望检索
_ -Properties mail} | Select SAMAccountName,mail | Export-CSV C:\all.csv -NoTypeInformation instead.

(That's if you wish to retrieve their email.)


这篇关于从CSV导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆