I have a script that executes three separate code blocks. The first block performs a query and then creates a text file with the results. The second block performs a second query and then attempts to append it's results to the text file originally created in the first block. The second block ends up failing because a process in the first block still holds the file open. What is proper way to close out this connection before moving onto the next code block? I am using out-file. Thanks for any help that is given.
The Out-File cmdlet normally takes care of the opening and closing of the file.
Could you perhaps include the code block skeletons (with the Out-File cmdlets) ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The initial creation of the file is shown below, and the second block is the same format as the first just with the -append option.
Get-VM | Get-Snapshot | select VM, Name, Created | Out-File c:\scripts\scriptlog\vmwarereport.txt
This works fine for me, even if I put the out-file commands on the same line
get-vm | out-file test.txt ; get-vmhost | Out-File -append test.txt
Maybe something like a virus scanner is holding the file open longer than usual?
Same here, works for me without a problem.
From where do you run the script ? PS prompt, PowerCLI prompt, a GUI...
What is the exact message you get ?
What version of PowerShell and the PowerCLI are you using ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I was running it through PowerGui and after running process monitor it looked as if PowerGui wasn't releasing the file. I ran it the regular way and everything worked as it should. Thanks for the help.
PowerGUI is not working as intended . Would you mind posting the bug and your script text on the PowerGUI.org forums so we can fix the problem?