When trying to execute the POST to /api/command according to this description the following error occurs:
PS C:\\> $Result.Error
remove-item : The Win32 int
If the accepted answer isn't appropriate for your situation (i.e. you don't want to use -Recurse
on the call to Remove-Item
because that would blast an item you want to exclude from deletion, when its containing folder is recursively deleted), the following worked for me:
Get-ChildItem d:\mypath -Recurse -Exclude FileToExclude.ext | Select -ExpandProperty FullName | sort length -Descending | foreach { Remove-Item -Path "$_" -Force }
It seems that simply piping the file object to Remove-Item doesn't work because of this bug, but piping the full filename and then using that as the -Path argument, gets around it.