скрипт показывающий имена пользоватлей не логинившихся в AD N-ное количество дней.

Запись создана марта 12, 2008

//~~Author~~. Paul stuart
//~~Email_Address~~. Paul.Stuart@schroders.com
//~~Script_Type~~. Jscript
//~~Sub_Type~~. DomainAdministration
//~~Keywords~~. ADSI, last login date, domain, login

//~~Comment~~.
//Create a report showing users who haven't logged in to the Domain for X days or more.
//Requires ADSI 2.5 and Jscript version 5. The results are sent to LOGFILE.TXT

//~~Script~~.

var sDomain = ""; // enter your domain here.
var iCutOffDays = 0; // last login cut-off in days.

var TRUE = 1;
var ForReading = 1;
var ForWriting = 2;
var DAYMSECS = 86400000; // number of milliseconds in a day
var DomObj, CollObj, sSubDir;
var iNumUsers = 0;
var CutOff;

var WSHShell = new ActiveXObject("WScript.Shell");
var fs = new ActiveXObject("Scripting.FileSystemObject");

WSHShell.Popup("Starting Last Log Report " );

CutOff = new Date();
CutOff.setTime( CutOff.valueOf() - iCutOffDays*DAYMSECS );

DomObj = GetObject("WinNT://" + sDomain );
CollObj = new Enumerator(DomObj);

for ( ; !CollObj.atEnd(); CollObj.moveNext())
{
var Obj = CollObj.item();
if ( Obj.Class == "User" )
{
iNumUsers++;
try
{
if ( Obj.LastLogin < CutOff.valueOf() )
WriteLOG( Obj.name + " " + Obj.LastLogin );
}
catch( ErrorObj )
{
WriteLOG( Obj.name + " has never logged in" );
}
}
}

WriteLOG("Total number of users is " + iNumUsers );

WSHShell.Popup("Finished");
WScript.Quit();

//////////////////////////////////////////////////////////////////////////////////
// WriteLOG
//
var LogFile = new Object();

function WriteLOG( sLogLine )
{
var d = new Date();

if ( LogFile == null )
{
LogFile = fs.OpenTextFile( ".\\Logfile.txt" , ForWriting, TRUE );
LogFile.WriteLine( sLogLine );
}
else
{
LogFile.WriteLine( sLogLine );
}
}

» Запись из раздела windows | Комментировать

Комментарии





Ответить