Hi everyone,
Is anyone able to assist me with this if possible. The script below works fine. I put the AD accounts to be deleted in the "To Delete" OU and it deletes all the corresponding profiles and userdata of those AD accounts in the "To Delete" OU from the Servers.
but the only issue is: I can only delete the files from the servers if I have "ownership" permissions of the "Profile" and "userdata" to be deleted.
Can someone help me amend the script below so I can automatically take ownership of these "folders and files" (on the Server) of the AD accounts I put into the "To Delete" OU. I have put in the "C drive" location in the script as a test.
Any help will be much appreciated!
---------------------------------------------------------
Option Explicit
Dim strOU, objOU, objFSO, objUser, strUserData
' Specify the OU.
strOU = "ou=To Delete,dc=rcm,dc=ac,dc=uk"
' Bind to the OU.
Set objOU = GetObject("LDAP://" & strOU)
' Use FileSystemObject to delete folders.
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Filter on user objects.
objOU.Filter = Array("user")
' Enumerate users.
For Each objUser In objOU
' Skip computers (which have class user).
If (objUser.Class = "user") Then
' Delete user profile path.
If (objUser.profilePath <> "C:\profiles") Then
If (objFSO.FolderExists(objUser.profilePath) = True) Then
objFSO.DeleteFolder(objUser.profilePath)
End If
End If
' Delete the user object from AD.
objUser.DeleteObject (0)
End If
' Delete userdata.
strUserData = "C:\userdata" & objUser.sAMAccountName
If (objFSO.FolderExists(strUserData) = True) Then
objFSO.DeleteFolder(strUserData)
End If
Next
----------------------------------------------
Many thanks.
Fong
Is anyone able to assist me with this if possible. The script below works fine. I put the AD accounts to be deleted in the "To Delete" OU and it deletes all the corresponding profiles and userdata of those AD accounts in the "To Delete" OU from the Servers.
but the only issue is: I can only delete the files from the servers if I have "ownership" permissions of the "Profile" and "userdata" to be deleted.
Can someone help me amend the script below so I can automatically take ownership of these "folders and files" (on the Server) of the AD accounts I put into the "To Delete" OU. I have put in the "C drive" location in the script as a test.
Any help will be much appreciated!
---------------------------------------------------------
Option Explicit
Dim strOU, objOU, objFSO, objUser, strUserData
' Specify the OU.
strOU = "ou=To Delete,dc=rcm,dc=ac,dc=uk"
' Bind to the OU.
Set objOU = GetObject("LDAP://" & strOU)
' Use FileSystemObject to delete folders.
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Filter on user objects.
objOU.Filter = Array("user")
' Enumerate users.
For Each objUser In objOU
' Skip computers (which have class user).
If (objUser.Class = "user") Then
' Delete user profile path.
If (objUser.profilePath <> "C:\profiles") Then
If (objFSO.FolderExists(objUser.profilePath) = True) Then
objFSO.DeleteFolder(objUser.profilePath)
End If
End If
' Delete the user object from AD.
objUser.DeleteObject (0)
End If
' Delete userdata.
strUserData = "C:\userdata" & objUser.sAMAccountName
If (objFSO.FolderExists(strUserData) = True) Then
objFSO.DeleteFolder(strUserData)
End If
Next
----------------------------------------------
Many thanks.
Fong