【发布时间】:2010-11-19 23:41:24
【问题描述】:
我承认我是一个 powershell n00b,但需要根据来自 Novell 电子目录的 ldap 信息在广告中创建 12k 启用邮件的联系人。我一直在尝试操作以下代码以满足需要,但我一直在尝试拆分用户对象的“邮件”属性:
$gwise = "GWISE"
$comma = ","
$dot = "."
$space = " "
$gwcontacts = "C`:\Windows\System32\adfind.exe `-hh nds.groupwise.local `-simple `-s subtree `-nodn `-csv empty `-csvnoq `-b `"OU`=people,OU`=GroupWise,O`=local`" `-f mail=* mail givenName sn | findstr /i /c`:`"@`" | sort" | cmd | ConvertFrom-Csv -UseCulture -Header $header
alisdair 向我展示了如何在 powershell 中进行替换,但现在我很难弄清楚如何解析邮件属性,以便我可以只使用 @ 字符左侧的字符串:
$gwcontacts | ForEach-Object { New-MailContact -Name ($_.mail.split('@') + $dot + $gwise) -Alias ($_.mail.split('@')) -DisplayName ($_.sn + $comma + $space+ $_.givenName) -ExternalEmailAddress ($_.mail.Replace('GroupWise.local','example.com')) -FirstName $_.givenName -LastName $_.sn -OrganizationalUnit 'exchange.local/contacts' -PrimarySmtpAddress ($_.mail.replace('GroupWise.local','example.com')) }
Invoke-Command:无法将参数“别名”绑定到目标。异常设置“别名”:“属性表达式“TESTUSER GroupWise.local”无效。有效值为:由 A 到 Z(大写或小写)字符、0 到 9 数字、!、#、$、 %, &, ', *, +, -, /, =, ?, ^, _,
, {, |, } or ~. One or more periods may be embedded in an alias, but each period should be preceded and followed by at least one of the other characters. Unicode characters from U+00A1 to U+00FF are also valid in an alias, but they will be mapped to a best-fit US-ASCII string in the e-mail address, which is generated from such an alias." At C:\Users\Administrator\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\ems.exchange.local\ems.exchange.local.psm1:28521 char:29 + $scriptCmd = { & <<<< $script:InvokeCommand+ CategoryInfo : WriteError: (:) [New-MailContact], ParameterBindingException + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.Exchange.Management.RecipientTasks.NewMailContact
我知道我的拆分语法不正确...但是,我迷路了。任何帮助表示赞赏!
【问题讨论】:
标签: powershell