Tag Archives: vbs

Install printers

Many times we have the perennial problem in Active Directory environments that occasionally a user session on a machine that is not his usual, this causes without designated network printers to install printers, you can use this script:
one file instalar.bat that installs the printer, use the microsoft script prnmngr.vbs , first check that the printer is not connected in this case\\servidor\impressorared, if there is then installed on another call at the same script
Finally use the scriptdefprinter.vbs, establishing it as the default

 REM ***** Check and Install Copier*****
cscript prnmngr.vbs -l | find "Printer name \\servidor\impressorared"
IF ERRORLEVEL 1 ( cscript prnmngr.vbs -ac -p "\\servidor\impressorared"
echo "\\iocor\fax installed"
)
cscript defprinter.vbs \\servidor\impressorared

the script defprinter.vbs:

Option Explicit
dim objArgs
Set objArgs = WScript.Arguments
Dim objPrinter
Set objPrinter = CreateObject("WScript.Network")
objPrinter.SetDefaultPrinter objArgs(0)
' End of example VBScript
Facebooktwitterredditpinterestlinkedinmail

Read More ...

Automated users creation

This simple script (useful for workgroup environments), is useful for generating users have in a text file users.txt this file has the following 2 fields for each line are separated by commas: user, password, example would be this::
pepito,passworddepepito
jaimito,passworddejaimito
joselito,passworddejoselito
….
the script reads the file and generates the user adds them to the Administrators group and sets the password expiration to never.

' get local computer name
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("usuarios.txt", ForReading)
Do Until objTextFile.AtEndOfStream
  strNextLine = objTextFile.Readline
  arrServiceList = Split(strNextLine , ",")
  strAccount=arrServiceList(0)
  strPswd=arrServiceList(1)
  ' check if local account already exists
  intExists = 0
  Set colAccounts = GetObject("WinNT://" & strComputer & "")
  colAccounts.Filter = Array("user")
  For Each objUser In colAccounts
    If objUser.Name = strAccount Then
       intExists = 1
    End If
Next
If intExists = 0 Then
  ' create local user
  Set colAccounts = GetObject("WinNT://" & strComputer & "")
  Set objUser = colAccounts.Create("user", strAccount)
  ' set pswd
  objUser.SetPassword strPswd
  objUser.SetInfo
  ' set pswd never expires
  Set objUser = GetObject("WinNT://" & strComputer & "/" & strAccount & ",User")
  objUserFlags = objUser.Get("UserFlags")
  objPasswordExpirationFlag = objUserFlags Or ADS_UF_DONT_EXPIRE_PASSWD
  objUser.Put "userFlags", objPasswordExpirationFlag
  objUser.SetInfo
  ' add to local admins group
  Set objGroup = GetObject("WinNT://" & strComputer & "/Administradores,group")
  Set objUser = GetObject("WinNT://" & strComputer & "/" & strAccount & ",user")
  objGroup.Add(objUser.ADsPath)
End If
Loop
Facebooktwitterredditpinterestlinkedinmail

Read More ...

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
Facebooktwitterredditpinterestlinkedinmail

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

 

 

Facebooktwitterredditpinterestlinkedinmail

Read More ...

Categories

Subscribe to my Newsletter




By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close