Apr 21

WMI is microsoft’s attempt at making SNMP “better”. Whether they succeed or fail at that is subjective, but querying wmi from a non windows hosts has been a problem in the past and has required lots of hoops and weird proxies. No more! wmic is a command line wmi client that you can install on linux. On a debian based host, just use

apt-get install wmi-client.

Once installed, a simple test like the following should get you lots of wmi goodies. Just remember that you need to use a valid windows account that has permissions to query wmi for this to work.

wmic -U $DOMAIN/$USER%$PASSWORD //$SERVER “Select * from Win32_Service”

$DOMAIN is your AD domain where your user exists
$USER is your username
$PASSWORD is your users password
$SERVER is the server name

A real world example

jason@workstation:~$ wmic -U AD/jason%ohnoes //server.cyborgworkshop.org “Select ProcessID,Started,State from Win32_Service where Name=\”Dhcp\”"

Note that I escaped (\) the quotes on DHCP. It’s important. Do it.

Outputs

CLASS: Win32_Service
Name|ProcessId|Started|State
Dhcp|1196|True|Running

Mar 6

Sometimes you just need to add a single additional IP to a windows machine. While you can do that via the gui, it’s cumbersome and slow. A quick little bit of command line magic will do the job just fine.

To add a primary IP, do this

netsh int ip set address “Interface Name” static IP NETMASK GATEWAY METRIC

For a secondary address or virtual IP

netsh int ip add address “Interface Name” IP NETMASK

To add a DNS server

netsh int ip add dns “Interface Name” IP

And you’re done!

Oct 14

Good old uptime doesn’t exist on windows boxes (you get to pick if I’m being literal or figurative), so in order to get the time since last reboot on a windows machine, fire up the command prompt and run this.

net stats srv

You’ll get a bunch of stuff back, but way at the top will be a line similar to

Statistics since 3/18/2008 3:42 AM

That’s the last time the server was rebooted.

Oct 8

When you need to restart windows from the command line, say from a remote desktop session, you can use the following commands from the windows command line to accomplish that goal.

To restart

shutdown -r -t 01

Or to shutdown

shutdown -s -t 01

Apr 18

When you need to get ip address information from a windows machine, the quickest way is to use the ipconfig command from a command prompt. Go to start, then run and type

cmd

then run

ipconfig /all

will give you most of the information you’ll need to figure out how the network stack is configured on a windows machine including the hostname, IP, dns servers, netmask, etc.