I'm running a playbook against a Windows VM to delete the contents of the recycle bin and the task runs successfully signifying that a change has been made. However, when looking on the server itself, the contents of the recycle bin still remain.
There are several ways to delete the contents of the recycle bin. Here are the following methods I've tried:
Different Ansible playbooks used:
- name: Clean recycle bin
win_shell: |
$recycleBin = (New-Object -ComObject Shell.Application).NameSpace(0xa)
$recycleBin.Items() | ForEach-Object -Process { Remove-Item -Path $_.Path -Force -Recurse }
- name: Clean recycle bin
win_shell: Clear-RecycleBin -Force
- name: Clean recycle bin
win_command: cmd.exe /k rd /s /q %systemdrive%\$Recycle.Bin
Using the powershell commands, it will delete everything without prompting me to confirm.
I would prefer not to run the cmd.exe
command, since it only deletes the contents that pertain to the C:\ drive, unless I specify the drive letter.
All these commands successfully delete the contents of the recycle bin when run on the server itself but when using Ansible, the contents of the recycle bin remain.