I need to delete several user shares when I delete AD accounts (more than just a simple home drive deletion, we also need to delete terminal services profiles, and other things for custom apps). I have created some custom commands that as simple powershell scripts that run the following code
Remove-Item \\server\share\%username% -Force -Confirm:$False
As a part of the AD Account deletion scheduled task, I have set these custom commands to run as a part of the task.
Everything in the account deletion process works, except for these custom commands. I think the problem may have to do with the fact that the account is deleted before these commands are run, therefore the commands don't work because they don't recognize the user account (since it is no longer present).
The adaxes activity history shows a failed status for the cusom command, and the execution log shows "Could not find a part of the path \\server\share\'.".
It's seems like it's leaving the %username% field empty. These custom commands work just fine when I test them by themselves with sample accounts.
Thoughts?