Search for a certain string or value in a session variable, modify it, and create a new session variable
I need to create a certain variable from some information i pull from someone's AD group. I am basically query AD for a users "memberOf" and this is what i get:
| CN=__P-GBL-Software-ComputerName3-Extranet-ExternalAccess,OU=Container,OU=Groups,OU=Acct_ABC,DC=company,DC=com | CN=Code Committee,OU=Distribution Groups,OU=Groups,OU=Acct_ABC,DC=company,DC=ccom | CN=__A-GBL-Dept-Switch-FULL,OU=Admins,OU=Acct_ABC,DC=company,DC=com | CN=__ABC Staff Lotto (Restricted),OU=Distribution Groups,OU=Groups,OU=Acct_ABC,DC=company,DC=com | CN=__P-GBL-Pix-Loc-Special,OU=Software,OU=Groups,OU=Acct_ABC,DC=company,DC=com | CN=__P-GBL-Pix-Role-Telehealth,OU=Software,OU=Groups,OU=Acct_ABC,DC=company,DC=com | CN=__P-GBL-Pix-Loc-House Home Health,OU=Software,OU=Groups,OU=Acct_ABC,DC=company,DC=com | CN=Talking Email,OU=Distribution Groups,OU=Groups,OU=Acct_ABC,DC=company,DC=com | CN=ABC-MS-O365-E3-Reporting,OU=Azure,OU=Groups,OU=Acct_ABC,DC=company,DC=com | CN=__P-GBL-F5-Test,OU=Groups,OU=Acct_ABC,DC=company,DC=com |
I need to pull the computer name from this long list and this value can be dynamic and the number "3" could be single digit or two digits like a "12". The value "Container" is unique and i think i can start here. I was hoping to find the string that contained "Container", then separate the vlues by "-" and from "-" take the values behind it.
Example, first find the first string using "Container":
CN=__P-GBL-Software-ComputerName3-Extranet-ExternalAccess,OU=Container,OU=Groups,OU=Acct_ABC,DC=company,DC=com
Next separate by "-":
CN=__P-GBL
Software
ComputerName3
Extranet
ExternalAccess,OU=Container,OU=Groups,OU=Acct_ABC,DC=company,DC=com
And create a variable using ComputerName3. I have looked the different "Split" and "lindex" commands but it can be a little confusing. Any help?