Move Item, cannot acces file (in use)
I've edited the following function to read the productname instead and write it to a text file, this is working great.
https://gist.github.com/codeassassin/913062
Now I want to move the MSI it read to a different folder using the Move-Item command.
I keep however getting the following error:
Move-Item : The process cannot access the file because it is being used by another process. At E:\MSI2APPV\Client\MSI2APPv.ps1:4 char:1 + Move-Item "$Path" ".\Done\" +CategoryInfo :WriteError <E:\MSI2APPV\Client\MSIS\CCleaner.msi:FileInfo> [Move-Item], IOException +FullyQualifiedErrorId: MoveFileInfoItemIOError,Microsoft.PowerShell.Command.MoveItemCommand
This is what's supposed to move the MSI:
$Msi = Get-ChildItem .\MSIS\| Where-Object {$_.Extension -eq ".msi"} | Select-Object -first 1 $Path = ".\MSIS\$Msi" Move-Item "$Path" ".\DONE"
Any help would be great.
0 Comments
[ + ] Show comments
Answers (1)
Please log in to answer
Posted by:
jaybee96
11 years ago
it is probably still open by the previous function to get the ProductName?
Comments:
-
That's what I thought but how do I close it? - Celahir 11 years ago
-
http://msdn.microsoft.com/en-us/library/system.management.automation.powershell.dispose(v=vs.85).aspx - jaybee96 11 years ago
-
No, that closes the PS instance. The OP needs to close the database which, off the top of my head, is achieved using the .Close method. As I believe I have mentioned once or twice before, the WI object model is fully documented on MSDN and in the SDK which, no doubt, you still haven't downloaded. - anonymous_9363 11 years ago
-
thanks vbscab.. I will take a look at that.. - jaybee96 11 years ago