May 042013
 

I was having a conversation with a colleague the other day about the many different ways to use Powershell and get-wmiobject to quickly tap into any WMI Class without having to source the work to vbscript. Gwmi gives you the opportunity to specify parameters and allow one to quickly attach to a remote PC or server and gather information about any class. Here is an example which will allow you to step through a given class on a remote computer and display the results to console.

  • Lets step through first and then provide the command line:
    • Open up command line > start > run > type in “cmd” and click on “OK”
    • type in “Powershell” and press enter
    • type in “gwmi -computer remoteHostname” without the quotes and press enter. The -computer parameter will allow us to specify the host we want to attach to.
    • You will now be prompted to enter a class. For this example type in “win32_computersystem” and press enter
    • Assuming the account you are using has rights to the remote computer/server, you will be displayed with information pertaining to the Win32_computersystem class (domain, manufacturer, model, name, primary owner name, total physical memory).
    • Now if you dont want to step through the code, simply key in the following command at the PS> prompt.
      • gwmi -class Win32_ComputerSystem -computer remotehostname
      • gwmi -class Win32_ComputerSystem -computer remotehostname -credential domain\LanID <– this will allow you to specify a specific user account to authenticate against.

Combining Powershell and WMI can be very useful. Add a dash of a hashtable and loop though a series of hosts and you have a recipe for a great looking script.

Oct 022012
 

There is a myriad of ways to get and set a remote computer, vm or servers timezone either by using the command line or a script of sorts. Most ways leverage the same core repository in some form or the other. In the event you need to quickly check the time zone of a remote host and don’t feel like using a script – simply use WMIC to accomplish your task.

To check timezone information use the following command:

remotePC would be the name or ip of the remote computer or server that you want to check. 

WMIC /node:remotePC Path Win32_TimeZone Get StandardName /Format:List

To check the timezone by command locally use:
WMIC Path Win32_TimeZone Get StandardName /Format:List

Now to set the timezone remotely using WMIC use the following command:

To set the timezone locally use:
WMIC ComputerSystem SET CurrentTimeZone=*(see below)

To set the timezone remotely use:
WMIC /:node:remotePC ComputerSystem SET CurrentTimeZone=*(see below)

We put the * in the above command line because there is some quick math we need to do.We simply just need to determine the UTZ offset.

  • If the timezone we wanted to set were in Eastern Time (US & Canada) we would ust the following command:
    • WMIC ComputerSystem SET CurrentTimeZone=-300
    • GMT = 0, so to get our value we would take GMT -5 (eastern) and multiply as follows: (-5:00 is -60*5 = -300)
  • If the timezone we wanted to set were in Cairo, which happens to be UTC:+02:00. And to get our CurrentTimeZone value we would use (+2:00 is 60*2 = 120)
    • Our command would be WMIC ComputerSystem SET CurrentTimeZone=120
Aug 292012
 

Yep – we have a folder somewhere with an onslaught of scripts that do this and that, but somehow we found it necessary to do a quick google search and see if we can gather a script which will allow us to check our VM’s, Servers and desktops for availability. Rest assured, you have come to the right site. To check for free space via WMI here is a simple script to accomplish your task.

remoteAsset = "."
Summary = 0

Set objWMIService = GetObject("winmgmts:\\" & RemoteAsset & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery ("Select * from Win32_PerfFormattedData_PerfDisk_LogicalDisk where Name = '_Total'")
For Each Driveletter in colDisks
     Summary = Summary + Driveletter.FreeMegabytes
Next
Summary = Summary / 1024
Summary = Round(Summary)

Wscript.Echo "Free space: " & Summary & " GB"

Continue reading “Checking drive space with WMI” »

Optimized by SEO Ultimate