Array from Computer description in Active Directory

I’m using PowerShell to get the Computer description from Active Directory.  (This part is working fine) At our company we use the computer description in AD to help with tracking PC. (Updated by a logon script)

 (  = (IP)(username)(ImageDate)

Open in new window

I want to use PowerShell to read the description and put the three items into an Array or something so I can do other lookups with them later in the script. However, i am not sure how to do that....

Any ideas or guidance is appreciated!!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Just so I can understand you want to be able to look for other things within the same script based on the values:


If so can you provide the current script you are using so I can probably modify it to add the functionality you need, where you need it.
POOK-101Author Commented:
i don't have it right now, (at the office) but it's very basic

1) Reads a txt file to get  the host names......  foreach ($pc in $list)

2) $CompDesc = Get-ADComputer -Identity $pc -Properties * | select Description

3) I was looking to use the middle (username) to look-up the Manager name.
ok I think I get what you mean, you want to use split the description into 3 parts

I am not sure what delimiter you use for the description field, but if there is a valid delimiter then you can simply use split e.g
$uname = $CompDesc.split(' ')[1]

The idea is (if non of the values contain spaces (Then we can use space as the delimiter)
You can then use the $uname variable for your next query.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
What were the top attacks of Q1 2018?

The Threat Lab team analyzes data from WatchGuard’s Firebox Feed, internal and partner threat intelligence, and a research honeynet, to provide insightful analysis about the top threats on the Internet. Check out our Q1 2018 report for smart, practical security advice today!

Considering description will be exactly as you mentioned.. (

#Your code to save the computer description to a variable
$CompDesc = Get-ADComputer -Identity $pc -Properties * | select Description

#To split the description in to three and save it in to a array variable $Arr
$Arr = $CompDesc.Description -replace "\(" -split "\)"

$arr[0] will give you the IP address

$arr[1] will give you the User Name Joe123

$arr[2] will give you the ImageDate Date:04/10/2013

#To get Manager
$Manager = (Get-ADUser (Get-ADUser $Arr[1] -Pr Manager).manager -Pr DisplayName).DisplayName
You could split the description (into an array) and from that either:  assign each portion to it's own variable; or you could use one variable to contains all the portions (elements).  becraig's idea is pretty much the way I would approach it.  You could target only one field of the description (as in his example), or you could capture them all (depending on your needs).  Assuming that the string you gave in the original question is representative of the format of the description field, here's an example of the capturing everthing.
$IP, $Manager, $ImageDate = ("(" -split "[()]{1,2}")[1..3]
# or using the variable that you gave, I would make a slight change
$CompDesc = Get-ADComputer -Identity $pc -Properties * | select -expand Description
$IP, $Manager, $ImageDate = ($CompDesc -split "[()]{1,2}")[1..3]

Open in new window

Side note - I would only use -properties * only during initial testing as it's more efficient to actually list which properties you need returned.

Edit:  I see that Subsun posted while I was typing up my comment.  His method is a bit closer to mine.
POOK-101Author Commented:
Perfect and well documented for someone that is learning PowerShell
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.