Windows Vista Forums

Here is ascript to gather general info on your computers in AD
  1. #1


    Jacob Sampson Guest

    Here is ascript to gather general info on your computers in AD

    In an effort to be as valuable to this community as it has been to me I am
    posting this script. I hope that it will be usefull to some. If this is the
    wrong place to do this sort of thing feel free to move it.

    Here is what the script does:
    1. Gathers all computers in your Active Directory Domain and loads them into
    a variable (maybe an array I am not sure.)
    2. Cycles through the array of computernames one by one and Pings them. If
    the ping is successfull then it gets the following info from that machine:
    a. Last logged on username
    b. Computer name
    c. what the OS is
    d. how much memory is installed
    e. What the Ip address is of the machine
    f. how much free space is left on the C:\
    3. It then writes this info to a tab seperated .csv file. It also write the
    computername and OS to the screen so that you can monitor the script as it
    runs.
    4. If the ping is not successfull then it writes the machines name to
    another file.

    This seems like it would be valuable from the standpoint of monitoring
    resources on your network as well as Cleaning out the guts of my script and
    putting your own guts in but already having the engine to scan all machines
    in any domain.

    $root = [ADSI]''
    $searcher = new-object System.DirectoryServices.DirectorySearcher($root)
    $searcher.filter = "(objectCategory=computer)"
    $searcher.pageSize=1000
    $searcher.propertiesToLoad.Add("name")
    $computers = $searcher.findall()

    foreach ($computer in $computers)
    {
    $computername = $computer.properties.name
    $ping = gwmi win32_pingstatus -f "Address = '$computername'"
    if ($ping.StatusCode -eq 0)
    {
    $registry =
    [Microsoft.Win32.RegistryKey]:penRemoteBaseKey("LocalMachine","$computername")

    $registrykey = $registry.openSubKey("Software\Microsoft\Windows
    NT\CurrentVersion\Winlogon")

    $LastUser = $registrykey.getValue("DefaultUserName")

    $OS = (gwmi Win32_OperatingSystem -computername $computername).caption

    $InstalledMemory = (gwmi win32_ComputerSystem -computername
    $computername).TotalPhysicalmemory/1024000000

    $FreeDiskSpace = (gwmi win32_logicaldisk -computername $computername -filter
    "Name='c:'").freespace/1075000000

    $IPAddress = $ping.ProtocolAddress

    out-file \\Servername\sharename\ScanningResults.csv -inputobject
    "$LastUser $computername $IPAddress $OS $InstalledMemory $FreeDiskSpace"
    -append

    "$Computername -- $OS"
    }
    Else
    {
    out-file \\Servername\sharename\PingFailedResults.csv
    -inputobject "$computername" -append
    }

    }



    P.S. After pasting this in I realized it is very ugly. There are many times
    where lines are split in two. If you have any questions about the script or
    would like me to email you a cleaner version feel free to send me an email.

    Jacob Sampson
    jsampson@xxxxxx

      My System SpecsSystem Spec

  2. #2


    Robert Aldwinckle Guest

    Re: Here is ascript to gather general info on your computers in AD

    "Jacob Sampson" <JacobSampson@xxxxxx> wrote in message
    news:6946F399-4DE2-4224-8481-5EA68BC3F437@xxxxxx

    > [X-Newsreader: Microsoft CDO for Windows 2000]
    ....

    > P.S. After pasting this in I realized it is very ugly. There are many times
    > where lines are split in two.

    Mostly because you are using that horribly deficient web interface to newsgroups.
    Get a real newsreader to have more options regarding linesize or even being able
    to post your code via attachments.

    E.g. with default settings on most Windows machines you could access this newsgroup
    via the following link, copied to and executed from the Run... dialog

    news://msnews.microsoft.com/microsof...ows.powershell

    Note: you may want to personalize the news account that using that creates
    before posting with it.


    HTH

    Robert Aldwinckle
    ---



      My System SpecsSystem Spec

  3. #3


    Jaykul Guest

    Re: Here is ascript to gather general info on your computers in AD

    Nothing wrong with sharing them here, but the best way to share scripts that
    are mostly complete would be to post them on http://PoshCode.org ... that
    way you wouldn't have to worry about the line-wrapping, etc.

    --
    Joel "Jaykul" Bennett
    http://HuddledMasses.org/
    qotd: Economists can certainly disappoint you. One said that the economy
    would turn up by the last quarter. Well, I'm down to mine and it hasn't. --
    Robert Orben


    "Jacob Sampson" <JacobSampson@xxxxxx> wrote in message
    news:6946F399-4DE2-4224-8481-5EA68BC3F437@xxxxxx

    > In an effort to be as valuable to this community as it has been to me I am
    > posting this script. I hope that it will be usefull to some. If this is
    > the
    > wrong place to do this sort of thing feel free to move it.
    ....

    > P.S. After pasting this in I realized it is very ugly. There are many
    > times
    > where lines are split in two. If you have any questions about the script
    > or
    > would like me to email you a cleaner version feel free to send me an
    > email.
    >
    > Jacob Sampson
    > jsampson@xxxxxx

      My System SpecsSystem Spec

Here is ascript to gather general info on your computers in AD problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is the script to convert domain computers to sbs computers? dsatchell SBS Server 2 24 Oct 2009
WMP11 playcount info usage in two computers Marko_77 Vista music pictures video 0 23 Jan 2008
general Info General info Vista Games 3 16 Jan 2008
Can 2 xp computers and 2 vista computers exist in a family network Cyndy A Vista networking & sharing 2 01 Jul 2007
Vista install fails during "Gather" =?Utf-8?B?R1c=?= Vista installation & setup 1 23 Sep 2006