Sunday, May 11, 2008

Dhcp or static ip address from script

Assign a static IP address to local area connection network interface:
netsh interface ip set address name= "Local Area Connection" static 192.168.1.2 255.255.255.0 192.168.1.1
netsh interface ip set dns "Local Area Connection" static 192.168.1.10 primary

Assign a dynamic allocated IP address to local area connection network interface:
netsh interface ip set address name="Local Area Connection" source=dhcp
netsh interface ip set dns name="Local Area Connection" source=dhcp

Date of user's last logon

Here is a little script which will give you the date of a user last logon. But first, I will thell you some things which will introduce you in the background of this problem.
Windows 2000 domain controllers save last logon date in the "lastlogon" attribute. This attribute is NOT replicated among all domain controllers in the domain and is listed in a wired format such as 12327435289, which means the number of 100 nanosecond intervals which have elapsed since 1/1/1601. So, if you have a domain level of Windows 2000, the following script is the way to do it. The script interogates a specific DC and return the value from this.
Windows 2003 domain controllers save last logon date in the "lastlogonTimestamp" attribute. This attribute IS replicated among all domain controllers in the domain.

Option Explicit
Dim objOU, objUser, objRootDSE, objLastLogon
Dim Container, Domain
Dim intLastLogonTime
Dim location
Container = "OU=Sales, " //Put here the desired OU
Domain = "DC=test,DC=com" //Put here your domain
location= Container & Domain
wscript.echo location
location = Container & Domain
set objOU =GetObject("LDAP://Desired DC to interogate/ " & Container & Domain)
For Each objUser In objOUSet
objLastLogon = objUser.Get("lastLogon")
intLastLogonTime = objLastLogon.HighPart * (2^32) + objLastLogon.LowPart
intLastLogonTime = intLastLogonTime / (60 * 10000000)
intLastLogonTime = intLastLogonTime / 1440
Wscript.Echo objUser.Name & " last logon time: " _
& intLastLogonTime + #1/1/1601#
Next
WScript.Quit

Thursday, January 31, 2008

Export RRAS configuration

This is a vey useful command line backup option i use it frequently.
netsh routing dump > Routing.txt
netsh RAS dump > RAS.txt
Then we can use netsh exec on another server to import the configuration.
If you want to export other settings, just look at other netsh command line switches.

Tuesday, January 29, 2008

System hardware information and uptime

Systeminfo is a useful tool to collect valuable system hardware information remotely.
For example, the following line will return the hardware information (System Model, System type, uptime, etc) of a remote server "remotemachine" and write them in "remotemachine.csv" file.
SYSTEMINFO /S remotemachine /FO csv >>remotemachine.csv

RRAS server logging and debugging

RRAS logging

To view who logged in, how long, etc you have to go to remote acces logging and on properties tab of the local file log, check authentication request. You will see in windows\system32\logfiles the results.

RRAS debugging

We can debug RAS connections using RAS logs. To enable RAS logs run command
netsh ras set tracing * enabled . Then, we check the logs at %windir%\tracing directory.
Error code related to RRAS are listed here http://support.microsoft.com/kb/q163111/
After we resolve the issue, we disable RAS logs by command:
netsh ras set tracing * disabled