VMware

This Question is Answered

1 "correct" answer available (10 pts)
6 Replies Last post: Jul 7, 2009 11:22 AM by dpenderg  

File Creation Process posted: Jul 6, 2009 8:18 AM

Click to view mittim12's profile Master 1,015 posts since
Mar 24, 2006
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.

Re: File Creation Process

1. Jul 6, 2009 9:20 AM in response to: mittim12
Click to view LucD's profile Champion vExpert 3,048 posts since
Oct 31, 2005
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) ?

Re: File Creation Process

3. Jul 6, 2009 11:08 AM in response to: mittim12
Click to view DougBaer's profile Expert 606 posts since
Oct 20, 2004
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?

Re: File Creation Process

4. Jul 6, 2009 11:54 AM in response to: mittim12
Click to view LucD's profile Champion vExpert 3,048 posts since
Oct 31, 2005
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 ?

Re: File Creation Process

6. Jul 7, 2009 11:22 AM in response to: mittim12
Click to view dpenderg's profile Lurker 1 posts since
Jun 4, 2008
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?

VMware Beta Programs

Want to be Considered for Future Beta Programs?

Learn More

VMware Developer

Download SDKs, APIs, videos,
training, and more in the Developer community.

Learn More

Developer
Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld
Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

Only VMware ... Delivers Nexus 1000V

Ensure consistent, policy-based network capabilities to virtual machines across your data center.

Learn More

Communities