Tag Archives: scripts

Delete files older than X days

this simple script ,shows how to delete files in a directory, older than 30 days old.

In this case delete the files that begin with “Backup” for more than 30 days from the directory D:\Backup

' ################################################################
' # cleanup-folder.vbs
' #
' # Removes all files older than 1 week
' # Authored by Jordi Colomé
' # Based on code by YellowShoe
' # Version 1.0 - Sept 23 2008
' ################################################################

Dim fso, f, f1, fc, strComments, strScanDir
' user variables
' —————————————————————-
strDir = "D:\Backup"
strDays = 30
' DO NOT EDIT BELOW THIS LINE
' (unless you know what you are doing)
'——————————————————————
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(strDir)
Set fc = f.Files

For Each f1 in fc
      If DateDiff("d", f1.DateCreated, Date) >strDays and (Left(f1.Name, 6) = "Backup")   Then
            fso.DeleteFile(f1)
      End If
Next
'wscript.echo strComments
WScript.Quit
' eof
Facebooktwittergoogle_plusredditpinterestlinkedinmail

Read More ...

Export Active Directory information

Many times we want to export information from Active Directory, to such an excel. To this end a very useful tool is the command CSVDE:

to see how it works it’s best to give some examples:

CSVDE -f usuarios.csv

Exports the object type ‘user’ and ‘computer’ Active Directory to a csv file

CSVDE -d “OU=Ejemplo,dc=es” r objectCategory=person -f usuarios.csv

Exports only objects ejemplo.es domain user type

CSVDE -f usuarios.csv -r “(&(objectClass=user)(sn=Pe*))”

Export users only objects where the name starts with “Pe” the “&” indicates a start logical “AND”

CSVDE -f usuarios.csv -r” (|(useraccountcontrol=20)(useraccountcontrol=30)(useraccountcontrol=333))”

Exports only objects where the userAccountControl field is equal to 20 or 30 or 333, the operator “|” indicates the logical initial “O”

CSVDE -f usuarios.csv  -l “DN, objectclass, objectcategory, givenName, sn”

Exports only the selected columns to see all selectable attributes of an object such person, a very useful page is:

Microsoft ldap person reference

 

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Read More ...