Hi Everyone,
I have written a VBScript to delete userfiles/data. But the issue is when I run my script I receive the following error:
line: 24
Char:18
Error: permission denied.
I'm pretty sure the problem is that I do not have "Ownership" permissions of some of the profiles thus receiving the error access is denied. May you help amend my script so I can take ownership of these profiles?
Can I use wshShell.run with setacl.exe?
Many thanks for your help. Fong
-------------------------------------------------
Option Explicit
Dim strOU, objOU, objFSO, objUser, strUserData
' Specify the OU.
strOU = "ou=StudentsToDelete,ou=Default,ou=People,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 <> "\\rcm-file\stuprofs$\") 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 = "\\rcm-file\studuser$\" & objUser.sAMAccountName
If (objFSO.FolderExists(strUserData) = True) Then
objFSO.DeleteFolder(strUserData)
End If
' Delete userprofile if path not specified.
strUserData = "\\rcm-file\stuprofs$\" & objUser.sAMAccountName
If (objFSO.FolderExists(strUserData) = True) Then
objFSO.DeleteFolder(strUserData)
End If
Next
I have written a VBScript to delete userfiles/data. But the issue is when I run my script I receive the following error:
line: 24
Char:18
Error: permission denied.
I'm pretty sure the problem is that I do not have "Ownership" permissions of some of the profiles thus receiving the error access is denied. May you help amend my script so I can take ownership of these profiles?
Can I use wshShell.run with setacl.exe?
Many thanks for your help. Fong
-------------------------------------------------
Option Explicit
Dim strOU, objOU, objFSO, objUser, strUserData
' Specify the OU.
strOU = "ou=StudentsToDelete,ou=Default,ou=People,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 <> "\\rcm-file\stuprofs$\") 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 = "\\rcm-file\studuser$\" & objUser.sAMAccountName
If (objFSO.FolderExists(strUserData) = True) Then
objFSO.DeleteFolder(strUserData)
End If
' Delete userprofile if path not specified.
strUserData = "\\rcm-file\stuprofs$\" & objUser.sAMAccountName
If (objFSO.FolderExists(strUserData) = True) Then
objFSO.DeleteFolder(strUserData)
End If
Next