Import-DbaCsv keeping lock on file after execution
ALZDBA opened this issue · 0 comments
Bug Report
General Troubleshooting steps
- Verified running the latest release of dbachecks?
Does (Find-Module dbachecks).Version match (Get-Module dbachecks).Version.ToString()
CommandType Name Version Source
Function Import-DbaCsv 1.1.134 dbatools
- Verified errors are not related to permissions?
- Can duplicate in new/clean PowerShell session (clean =
powershell -NoProfile
)?
Version Information
- Operating System (Name|Version):
- PowerShell Version:
- SQL Server (Edition|Version):
Steps to Reproduce
<--
PLEASE include as much information as possible if this is a bug report.
The more you include the faster we can identify the problem and get it fixed
-->
- Attach any screenshots (if possible/allowed)
- Attach output from PowerShell console (if possible/allowed)
Description of Bug
<--
PLEASE include as much information as possible if this is a bug
Explain what it does that you would like it not to do
or
What it doesnt do that you would like it to do :-)
-->
$AllCSV = Get-ChildItem -Path $SourceFolder -Filter '*.csv' | Select -ExpandProperty Fullname | sort
foreach ( $csv in $AllCSV ) {
Import-DbaCsv -path $csv -SqlInstance $MyAppConfig.SQLServer -SqlCredential $cred
Move-Item -Path $csv -Destination $ArchiveFolder -Force ;
}
Move-Item : The process cannot access the file because it is being used by another process.
At C:\Users\itsme\Documents\Powershell\DEV\Import-Results\Import-Events2SQLServer.ps1:275 char:17
- ... Move-Item -Path $csv -Destination $ArchiveFolder -Force ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : WriteError: (C:\Res...0922_130643.csv:FileInfo) [Move-Item], IOException
- FullyQualifiedErrorId : MoveFileInfoItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand