/* ]]> */
Mar 252011
 

Here we have GetHostInfo.ps1 – a full-featured wmi query script that you can use to retrieve data from a remote (or local) machine. The script can pull details from the following WMI classes:

  • Win32_OperatingSystem
  • Win32_ComputerSystem
  • Win32_NetworkAdapter plus associated Win32_NetworkAdapterConfiguration
    (this is done by associating Win32_NetworkAdapter.DeviceId with Win32_NetworkAdapterConfiguration.Index)
  • Win32_LogicalDisk
  • Win32_PhysicalMemory
  • Win32_Processor
  • Win32_PageFileSetting

The script can also query the local administrators group members using ADSI.  Note that ADSI calls does not have the ability to use alternate credentials so you can only query this information using your current logged-on credentials. If the logged-on credential don’t have access, you will get an “access denied” error on the ADSI calls.

All data is nicely displayed in human-readable format; e.g. Disk Space and Memory translated to GigaBytes and Tabular output where appropriate. You also have the ability to use alternate credentials if necessary (using the -Cred parameter). The -Cred parameter can be used interactively or with an encoded credentials file (see my other post for details on the Export-PSCredential and Import-PSCredential functions) .

One other note, the Win32_Processor output is in tabular format and can be quite wide; to avoid having data truncated, I suggest setting your console window width to about 160 characters.

Here are some sample outputs:

Win32_OperatingSystem

Win32_ComputerSystem

Win32_NetworkAdpater + Win32_NetworkAdapterConfiguration

Win32_LogicalDisk

Win32_PhysicalMemory

Win32_Processor

So, the best way to get started with this is to download the script and start using it.

Be aware that you can always use the “-Help” parameter for usage details:

 

 Posted by at 12:41 pm

  4 Responses to “GetHostInfo – Remote Host Query Script using WMI”

  1. Very usefull script and it works great.

    Thanks for sharing.

  2. Hi,

    Please can you update the script for getting the hostname from the text file and then export the output in html file.

    Regards,
    Shashi

  3. Hi Sashi,

    We don’t really need to modify the script to process a list of hostnames. You can achieve the same thing by calling the script from within a looping construct. Something like this ought to work:

    gc .\MyHostFile.txt |% {“nResults for: $_n”; ./gethostinfo.ps1 $_}

    For HTML output you could wrap the output from the above code with some HTML tags.

    something like this:

    “<html><head></head><body><pre>” | out-file  hostfile.html
    gc .\MyHostFile.txt |% {“nResults for: $_n”; ./gethostinfo.ps1 $_} |out-file -append hostfile.html
    “</pre></body></html>” |out-file -append hostfile.html

    One note, you would need to modify the WriteHeader function to write to stdout so that the headers can be captured to your html file. The write-host cmdlet forces output to go only to the console.

    Hope This Helps!

  4. Simply fantastic. I wish I could script as well as you. Thanks so much!!!

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Page optimized by WP Minify WordPress Plugin