Find & Replace Script for Text Files with Environment Variables
Posted on 2012-09-06
Good Morning -
I've got an issue with many text based files from SCCM 2012 which I'm trying to find a workaround for.
Long story short, it's Software Metering function often creates a text based file per machine and is placed in a "process" folder for processing. All of these files are not being processed due to the error of my domain's netbios name having an "&" in it. Therefore the files is moved to a "corrupt" folder indefinatly. However, I think if I find a way to change all netbios references to FQDNs, then it will work.
Therefore, I need to find a way to do the following:
- Single (but long) text based file with .MUX extension
- Has many netbios references like "UserName="AB&C_CN\variable"
- The variable can be hostname or username, but is always one complete word
- All instances of "AB&C_CN\variable" need to be replaced with the domain's FQDN of "variable.mynetwork.com" throughout file
- Each individual file has the same variable after the netbios name, but the variable is different per file.
- Once find / replace is complete, the file would need to be moved from it's current path (D:\Program Files\Microsoft Configuration Manager\inboxes\swmproc.box\corrupt) to the "process" folder (D:\Program Files\Microsoft Configuration Manager\inboxes\swmproc.box\process)
Any suggestions on how this could be automated via script or other process? Thanks