May 172013
 

A question came up the other day: How can I use command line to recursively search every .log file on a server for a specific string? The answer is quite easy and only requires the use of the findstr command which is part of the default build for all Windows based operating systems.  The only caveat to all of this is the account running the command will need view rights on the files/folders involved in the string search. Otherwise it will just exit and provide an error.

The following command will allow you to recursively search all log files for the following (in order). Date(month/day), string “error”, and the string “jms”. Log data will then be both displayed via command prompt, and also recorded to ./results.text which will be in the same directory as the command was initiated.

findstr /pinsc:"2013-05" *.log | find /i "error" | find /i "jms" >> ./results.txt

Dates and strings in various log files can get messy. Some people will misplace the backslash or forward slash, and the date format will be in UNC or some difficult format to read. If you happen to find yourself in this predicament, use the following to help. Scenario is as follows – search for the year, followed by month, followed by day. Then echo the results of the search to a text file which will be stored directly on the root of c:\.

findstr /pinsc:"2013* | find /i "04/22" >> c:\0422.txt

Now thats it! all set!

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 232012
 

Using netsh, you can configure the firewall on Server Core 2008 R2. if you need to have the ability to remotely gather information on a server core, make sure “Remote Administration” is enabled on the systems firewall.

netsh advfirewall firewall set rule group="Remote Administration" new enable=yes

Now to have the ability to remotely manage the server and configure access for WMI.

netsh advfirewall firewall set rule group="windows management instrumentation (wmi)" new enable=yes

To allow for the ability to remotely manage a windows firewall on a fully installed Windows Server 2008 R2 with netsh.

netsh advfirewall set currentprofile settings remotemanagement enable

There are indeed many more ways to use netsh to your advantage.

 Posted by at 4:17 pm

Optimized by SEO Ultimate