开发者

using powershell to create csv with multiple delimiters

i'll admit i'm a powershell n00b, but need to create 12k mail-enabled contacts in ad based on ldap information from a novell edirectory. i've been trying to manipulate the following code to suit the need, but i'm stuck trying to split apart the 'mail' attribute of a user object:

$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 showed me how to do a replace in powershell, but now i'm experiencing difficulty figuring out how to parse the mail attribute so that i can use just the string to the left of the @ character:

$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 + $scr开发者_Python百科iptCmd = { & <<<< $script:InvokeCommand + CategoryInfo : WriteError: (:) [New-MailContact], ParameterBindingException + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.Exchange.Management.RecipientTasks.NewMailContact

i know my split syntax is incorrect... but, i'm lost. any help is appreciated!


I'm not totally sure I've read this right, but what you want to do is take the GroupWise address and for each user replace the local Groupwise part of the address with a proper internet domain?

To do it all in single line (assuming $gwaddress is a groupwise address, like user@local):

$internetaddress = $gwaddress.remove($gwaddress.indexof('@')).insert($gwaddress.indexof('@'),'@mydomain.com')

The code above takes the groupwise address, removes everything from the @ onwards, then appends your domain name from where the @ was in the original string.

Alternatively, if you just want to split the groupwise address into user and domain and build the internet address another way:

$gwuser,$gwdomain=$gwaddress.split('@')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜