Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Execute Delprof2.exe from Group Policy Logon Script

$
0
0

I would like to know if it is possible to remove stale local profiles from remote workstations that are older than 20 days.  These workstations are Windows 7, and possibly Windows XP.  Once an end user authenticates to the domain, it would launch the script via Group Policy (and if computer is part of OU) which should execute Delprof2.exe.

If there is a better practice, please let me know.

Currently, I think I can do the following:

 

OptionExplicitDim objOU, objComputer, strComputer, objShellDim strPath, intError 'Path to DelRrof2.exe. 
strPath = "\\share\support\Scripts\DelProf2.exe"' Number of days after which delprof considers the profile inactive and
 deletes. intDays = 20 ' Bind to the OU. Set objOU = GetObject("LDAP://ou=BuildOut_Delete,dc=domain_name,dc=org") ' Filter on objects of class computer. 
objOU.Filter = Array("computer") ' Use the Run method of the wshShell object. Set objShell = CreateObject("Wscript.Shell") ' Enumerate all computers in the OU. ForEach objComputer In objOU ' Retrieve the NetBIOS name of the computer. 
strComputer = objComputer.sAMAccountName ' Strip off trailing "$". 
strComputer = Left(strComputer, Len(strComputer) - 1) ' Run delprof.exe on the remote computer. 
intError = objShell.Run("%comspec% /c "& strPath & " /u /q /i /c:\\"& strComputer & " /d:"& CStr(intDays)If (intError <> 0) Then
Wscript.Echo "Error "& CStr(intError) & " on computer "& strComputerEndIfNext

 




Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>