Forum Discussion
I need help with PowerShell/ saving document files
Hello!
A little overview of the task I am trying to accomplish. The question I need help with is at the bottom.
I have found a way to merge my selected recipients in Word to individual documents. However, when I go to save I ran into a few issues.
First one being that I had to insert a greeting line as header to retain the first and last name, for saving file purposes. I inserted a comma after the last name to separate last, first for the file but Word doesn't see any data from the comma and data (first name) after the comma. So I deleted the comma.
So, I've been able to save the merged recipients as individual files, and because the header can only be so long, I use powershell to insert the date ex: 02.16.22 for each file.
Now the only issue I have now is inserting a comma between the Last and first name.
The documents save as Last First Group, then I use PowerShell to insert date, resulting with Last First Group Date. Ex: Dirt Joe OP 02.16.22
I have been manually inserting the comma for each file at a time, and the goal here is to minimize time, but seem to only be saving my sanity from repetitiveness of manually copying and pasting each name as individual documents.
The big question!
Is there a code to insert a comma after the first field of text in files?
6 Replies
- Could you show us a piece of the script and perhaps a sample output screenshot?
- CaslynRose96Copper Contributor
After I save the files, I save them into a separate folder from where they'll eventually end up, so I can apply to the powershell code to specific files. After I save, the files display as:
Next I insert the code to PowerShell that I found online somewhere.
I insert CA to be replaced, but I still need CA in the file name, So I make sure to put CA back into what will be replacing CA.
The code I use, I found online somewhere.
dir | rename-item -NewName {$_.name -replace " ","_"}
After I press enter It looks like this^^ Sometimes I will get an error with a bunch of red letters, but that is because it is informing that it was unable to apply code to some files or folders, because they don't have the CA data to replace. Any who, I got this far and the results look like this.
I want to add commas after the last name, because that is how my work needs files saved.
I could Avoid the whole coding thing entirely if Word could somehow retain my headers that have commas, and extend the length of text when saving.
This is how I have been doing my documents-->
This is how I have been creating my header, when I try to do single merge fields as header, Word doesn't retain all the text when saving. So I use greeting line. I have tried Inserting a comma after the last name within the recipient list, and the comma itself, no matter where it, manually or from the data source, word still doesn't see anything from the point of where the comma is inserted and everything after it.
Ill finish my steps to better explain what I mean.
I change the format so It isn't noticeable when saving, I change the font color to white and font size to be smaller.
After I create the greeting line, and uncheck names who don't need a document in saved It...
It opens in a new document,
I go to view > Outline > Then highlight all the content from where the header is, all the way down to the last person from my recipient list. The heading text is not visible (as I changed the color to white) but its there for saving purposes. AFTER I highlight all the content, I select Show Document > Create > File > Save as > Okay.
Then this is how it saves each individual file, with the last name first name and group name.
I use the code from the beginning to insert date to each file.
At first I tried to find a code that would recognize the specific lines the contain the first inserted merge fields with last name, first name, group, but I use the first names throughout the document, which makes think another obstacle. If I knew how to code, and had time to learn right now I would attempt creating it.
Any alternative ideas or suggestions would be greatly APPRECIATED! :))
Thank you for replying!