365 Powershell加载用户信息

时间:2015-03-30 13:27:24

标签: powershell office365

我是Exchange 365Powershell的新手。我有我想添加的用户信息,并尝试使用下面的Powershell代码。但是,它错误的出现在我身上。想法?

以下是代码:

$input=Import-Csv D:\Users.csv
foreach($line in $input)
{
Set-MsolUser -UserPrincipalName $line.UserPrincipalName -Title $line.Title -City $line.City -Country $line.Country -Department $line.Department -Fax $line.Fax -MobilePhone $line.MobilePhone -Office $line.Office -PhoneNumber $line.PhoneNumber -PostalCode $line.PostalCode -State $line.State -StreetAddress $line.StreetAddress
}

我得到的错误是:method invocation failed because system object doesn't contain a method Foreach

1 个答案:

答案 0 :(得分:0)

尝试直接管道化CSV,就像马特的建议:

Import-Csv D:\Users.csv | ForEach-Object{Set-MsolUser -UserPrincipalName $_.UserPrincipalName -Title $_.Title -City $_.City -Country $_.Country -Department $_.Department -Fax $_.Fax -MobilePhone $_.MobilePhone -Office $_.Office -PhoneNumber $_.PhoneNumber -PostalCode $_.PostalCode -State $_.State -StreetAddress $_.StreetAddress}