Array from Computer description in Active Directory

Posted on 2014-08-25
Medium Priority
Last Modified: 2014-08-27
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!!
Question by:POOK-101
LVL 29

Expert Comment

ID: 40284653
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.

Author Comment

ID: 40284713
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.
LVL 29

Accepted Solution

becraig earned 668 total points
ID: 40284736
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.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 40

Assisted Solution

Subsun earned 668 total points
ID: 40284940
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
LVL 41

Assisted Solution

footech earned 664 total points
ID: 40284958
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.

Author Closing Comment

ID: 40288157
Perfect and well documented for someone that is learning PowerShell

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Loops Section Overview

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question