私は自分のスクリプトに実装されている直接削除機能(直接ファイルを削除する)とゴミ箱削除機能(ゴミ箱に移動する)を持っています。ファイルをゴミ箱に移動
問題はゴミ箱の削除が機能しないことです。私はすでにthis suggested postを試しましたが、うまくいかないようです。
私の完全なスクリプト:PowerShellコンソールで
## Top of the script
param(
[Parameter(Mandatory=$true)]
[ValidateRange(0,99999)]
[int]$minutes,
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path $_})]
[string]$maplocation,
[Parameter(Mandatory=$true)]
[ValidateSet("Direct", "TrashBin")]
[string]$consequence
)
## error notifications
## Variables
$file = Get-ChildItem -Path $maplocation | Get-Date
$time = Get-Date
$minutesconvert = (New-Timespan -Start $file -End $time).TotalMinutes
foreach ($file in $files)
{
if ($minutes -lt $minutesconvert -and $consequence -eq "direct")
{
Write-Verbose "File Found $file" -Verbose
Write-Verbose "Deleting $file" -Verbose
Remove-Item $file.FullName
}
elseif ($minutes -lt $minutesconvert -and $consequence -eq "trashbin")
{
Add-Type -AssemblyName Microsoft.VisualBasic
Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($maplocation, 'OnlyErrorDialogs', 'SendToRecycleBin')
}
else
{
Write-Verbose -message "txt" -verbose
}
}
Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($maplocation, 'OnlyErrorDialogs', 'SendToRecycleBin')
エラーコード:
New-TimeSpan : Cannot convert 'System.Object[]' to the type 'System.DateTime' required by parameter 'Start'. The method is not supported. At C:\Users\david\Desktop\nieuw.ps1:21 char:39 + $minutesconvert = (New-TimeSpan -Start <<<< $file -End $time).TotalMinutes + CategoryInfo : InvalidArgument: (:) [New-TimeSpan], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.NewTimeSpanCommand
あなたは[受け入れられた回答](http://stackoverflow.com/a/503768/1163423)を試しましたか? –
「うまくいかない」より詳細を入力してください。何が起こるのですか?エラー?ファイルは完全に削除されますか? –
'$ maplocation =" C:\ Temp "' –