Array from Computer description in Active Directory

Posted on 2014-08-25
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 28

    Expert Comment

    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

    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 28

    Accepted Solution

    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.
    LVL 40

    Assisted Solution

    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 38

    Assisted Solution

    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

    Perfect and well documented for someone that is learning PowerShell

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
    Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now