Powershell write to a CSV while it's open - powershell

I have a process that will be running essentially 24/7. It will be writing data to a CSV but I want to be able to read that CSV periodically. The problem is that it seems like Export-Csv fails even when the file is opened in read only mode.
The CSV file in question is already marked as Read-Only so all writes I make to it in my script are using the force switch. This works fine but the second I open the file in excel (or even view it's properties in Windows Explorer) the script starts erroring out.
All I want to do is be able to do is write to a CSV with export-csv while also allowing that csv to be opened by excel in read only mode. Is this possible or do I need to come up with some method where I create a secondary copy of the file for viewing purposes?

The Office suite has the tendency to lock files it opens (I'm making this assumption because you're working with a CSV). If you open your file in notepad.exe, the problem you're experiencing will no longer happen.

Related

Can I use Powershell to copy text from another window?

I have OneDrive files which I can access through Microsoft Word or the browser, but not via a script. I need to pass the contents of one of these files as a variable for something later down the line in my script.
Googling this gives me lots of links explaining how to copy something from the Powershell window and paste it, which isn't what I want to do.
I need Powershell to open a Microsoft Word file, copy the text inside the file, and save the result as a text file. Is there any way to do that in Windows 10 with Powershell 5? I can't install any software.

How to modify a CSV file in Xcode Project Navigator

I'm currently working with a team that updates different rows and columns of a CSV file that lives locally in the app. The issue is that they have resorted to copying and pasting the entire CSV file into a new CSV file, modifying data and copying the edited CSV file and pasting it back into the project. I was curious if anyone had any suggestions on how they can edit the CSV file in Xcode without the complicated mess of copying and pasting.
P.S. Quick Look would prove useful if you could edit the CSV file in this mode.
One simple approach could be to have a reference to the file instead of a hard copy, this way each time you edit the file it should update on the project automatically. Look at this link for more refs: http://www.thomashanning.com/xcode-groups-folder-references/
This answer will only work if you have software such as Microsoft Excel on your computer.
In the Project Navigator, right click the csv file and select open with external editor. This will allow for Xcode to open the csv file using Excel. Modify any data as needed and save your work on Excel. Your csv file in Xcode will now reflect your changes made in Excel.

how to check if a .html file is open, if yes, close it using windows PowerShell script

I am new to PowerShell scripting. I would like to know if i can check whether a html file is open. If it is opened, then i would like to re-open it after running the same script.
My script creates a html file and using Invoke-Item, i am opening it. The next time i run the same script, the updated html file gets opened in the new tab. I want my script to close the previously opened file right before opening the new one or some similar logic.
By using Invoke-Item you actually are asking Windows' Explorer to open the file with the default application that's registered for .html files. In out of the box configuration, that's Internet Explorer or Edge. This, of course, can be customized.
Depending on the browser used, there might be a COM interface for querying browser status. As how to do that is subject to another a question, as it really depends on the browser. Looking for, say, file handles might or might not work, as browsers tend to open files in read only mode - they are not supposed to modify it anyway.
Anyway, this sounds like another a XY problem. Please edit the question and describe what problem are you really trying to solve; maybe there's better a way.

Possible to save a file in AutoHotKey script?

i want to save a .png file in to a AutoHotKey script, so that when i run the script it make the .png file.
i tryed to open the .png with notepad++ and copy the text in to a FileAppend command but there are just to many """ and "%" characters
I havent tested (1) and (2), but here are three different approaches:
modifying AutoHotkeySC.bin with a third-party tool like ressource hacker
building a .dll which you then might access via ahk
pack the complete file into your script and start its creation upon function calling. I saved this guy's V2.3 script up to pastebin. Works perfectly fine for me.
regards

How to check if a file on a network location is being written to, using PowerShell or other methods?

The thing that I am trying to do is I need to constantly check if a file on a shared corporate network location is available. The network admin performs a copy command and copies a large disk image file .iso to this target network location. The upload (copy) process takes about 4-5 hours, and in order to copy this file to my local computer, I need a way to determine whether this file has been fully copied or not.
I have tried using System.IO.fileinfo::Open, and it worked on my local experiment.
But yesterday when it checks, it failed to tell if the file is locked--the file is not constantly locked, and since it takes 5 hours, it seems that occasionally the file becomes unlocked briefly (possibly due to OS's trying to allocate another continuous space for that file). Hence my powershell script failed.
I also tried checking the size of the file as it is being copied over, but apparently the size of the file is constantly its original size, so this would not work.
So does anyone have any ideas how can this be verified? Thank you in advance.
There is a FileSystemWatcher but I am not sure if it works reliably on network folder. Another option is try check last write time of the file, and if the last write time is not changed for, say, 3 minutes, chances are that the copy is finished. You can also combine this with your lock check.