I am trying to figure out a way to close an open file via PS. I have a script that uses Start-Process to open a Java JAR file that encrypts data. The JAR completes the file encryption, then the process ends. However, the file it encrypted is open and I cant remove it using Remove-Item which is also part of the script.
Once the Script finishes, the file is unlocked and I can delete it. However, I need the PS script to delete the file. Using OpenFiles.EXE, I can see the file is open by Powershell.EXE and thusly I feel as though I should be able to unlock and delete the file, yet I am failing to find a way.
The likely first suggestion will be to use PS to encrypt the file, sadly, I MUST use the JAR file. I have a small function that detects if the file is locked using System.IO and it indeed reports the file is locked, I just have not found a way to unlock it using PS so I can delete it.
Thanks in advance for any help.