[How-To] Powershell command to move file to Recycle Bin | วิธี
-- ToC --
00:00:00 Install module Recycle
00:00:28 Create dummy file for test
00:00:56 Command to move to the recycle bin + Test run
00:01:39 Optionally create simple command
00:06:00 Verify the custom command result
00:06:47 Summerise again
00:14:26 In case of error Restricted Policy
1. Open Powershell as Admin
2. Type Command "Install-Module -Name Recycle"
2.1 See if no any errors as well
3. When you want to move some file to Recycle Bin, use this command
"Remove-ItemSafely ,file,"
4. [Optionally] make simple command via your Powershell Profile
4.1 New file "Microsoft.PowerShell_profile.ps1" at your documents folder, e.g. for mine is "E:\OneDrive\Documents" and in subfolder "WindowsPowerShell" or use $profile variable for the file path.
4.2 Code new function in this file
function delr {
Param($fname, $force=$false)
#for using with python os.system code because it needs to replace " " with "+" for helping separation of space characters
if (-Not (Test-Path $fname)) {
#replace "+" with " " for the argument from python os.system command
$fname=$fname.replace("+"," ")
}
Remove-ItemSafely $fname
}
4.3 Save the file
4.4 Run command "Powershell" again in the Powershell application window
4.5 If error about "Restricted execution policy", run this command in powershell "Get-ExecutionPolicy". It must shows result "Restricted"
4.6 You need to set new policy with this command "Set-ExecutionPolicy RemoteSigned"
4.7 Run the command "powershell" again to test it has no any errors