Working with the notes field of Active Directory (Posted in the wrong forum before....)

Hey, I have Problem with the data in my Active Directory notes field. The following code reads the notes field and splitts some Infos out of the string. That works fine in my test Environment. In the real Environment there is the Problem that the notes field isn't identic all the time, mostly the order of the subjects is different, example:

1. Notes Field: [A]LetterA [B]LetterB [C]LetterC #the text after the Letter in [] could be any Kind of text, or number, the letters are just examples

2. Notes Field: [C]LetterC [B]LetterB [A]LetterA #the text after the Letter in [] could be any Kind of text, or number, the letters are just examples

Actually I'm working with the following code:

$managedByUserGroup= #the current Group name

$LetterA = ($managedByUserGroup.info.Split("[]")[2]) $LetterB = ($managedByUserGroup.info.Split("[]")[6])

In consequence of the wrong order doesn't work it anymore....

Is it possible to run through the notes field and do something like:

If you found [A] save the text after [A] in $Letter[A], If you found [B] save the text after [B] in $Letter[B], same for [C], if you found nothing leave it blank.

Any ideas? 

Thanks for the help...!!!!  


July 2nd, 2013 7:11am

Try something like this:

$m = "[A]TextA[B]TextB" | select-string "\[([A-Za-z])\]([^\[]*)" -allmatches
$m | ForEach-Object { Set-Variable -Name $_.Groups[1].Value -Value $_.Groups[2].Value }

# Check result of variable $a
$a

This will use Regex to capture the letter (A-Z) between the braces [], and then also capture the text after the braces. It will do this for each set. After capturing the information, it looks over each set, and then uses Set-Variable to set the variable name to the value between the braces [], and set the variable value to the text.

Mike

Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2013 8:21am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics