以下是我正在尝试的代码:
[string] $Server= "ServerName"
[string] $Database = "DBName"
$UserSqlQuery= $("select FileDelete from DBName.dbo.tmp_TableName")
# declaration not necessary, but good practice
$resultsDataTable = New-Object System.Data.DataTable
$resultsDataTable.Columns.Add((New-Object System.Data.DataColumn 'FileDelete', ([string])))
$resultsDataTable = ExecuteSqlQuery $Server $Database $UserSqlQuery
Write-Host ("The table contains: " + $resultsDatatable.Rows.Count + " rows")
echo $resultsDatatable
$ RowDelete = $ resultsDatatable
foreach($RowDelete in $resultsDatatable)
{
echo "Inside For Loop"
echo $RowDelete
write-host “Deleting Duplicate PDF File/ Letter”;
# $RowDelete | foreach { $_.Delete()}
# $RowDelete | Remove-Item -Recurse -WhatIf -ErrorAction SilentlyContinue
Remove-Item -recurse -force $RowDelete -erroraction silentlycontinue -Whatif
}
DBName.dbo.tmp_TableName具有单个列,在共享驱动器上具有多个文件路径值。
通过$RowDelete
传递的实际路径示例为\\ccaintranet.com\Path\abc.pdf
。
代码正在运行,现在没有任何错误。但它不是从Windows文件夹中删除文件。
有人可以帮我诊断错误吗?
我从上面的命令中删除了SilentlyContinue选项,现在我看到以下错误消息 -
Remove-Item:找不到路径'Y:\ Data \ FS02-V \ Aetna \ ETL \ DataLoads \ RCE \ System.Data.DataRow',因为它不存在。 + Remove-Item<<<< -recurse -force $ RowDelete -Whatif + CategoryInfo:ObjectNotFound:(Y:\ Data \ FS02-V ... em.Data.DataRow:String)[Remove-Item],ItemNotFoundException + FullyQualifiedErrorId:PathNotFound,Microsoft.PowerShell.Commands .RemoveItemCommand
获取脚本的当前路径并且不接受通过$ RowDelete传递的路径