我承认我是powershell n00b,但需要基于来自novell edirectory的ldap信息在广告中创建12k已启用邮件的联系人。我一直在试图控制以下代码,以满足需要,但我卡住试图割断用户对象的“邮件”属性:使用powershell创建具有多个分隔符的csv
$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
阿利斯代尔告诉我如何做一个替换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 : Cannot bind parameter 'Alias' to the target. Exception setting "Alias": "Property expression "TESTUSER GroupWise.local" isn't valid. Valid values are: Strings formed with characters from A to Z (uppercase or lowercase), digits from 0 to 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
我知道我的分裂语法不正确...但是,我迷路了。任何帮助表示赞赏!
感谢阿利斯代尔,我相信这会工作。我想我会使用你的第二个建议......你会推荐重新构建一个新列的表,或者只是将它包含在我设置新的mailcontact值的foreach行中? – csp122 2010-11-17 21:05:58
我只是把它放在foreach循环中作为一开始的额外几行,否则你可能要做两个循环。你也可以在你的New-MailContact行中进行替换,如果它们都来自同一个域 - $ gwaddress.replace('local','mydomain.com') – craika 2010-11-18 11:05:52