Hi- I’m trying to get a script to work that will add multiple lines to a text file if they don’t already exist. I’ve got the script working to add the content, but for some reason it keeps adding the content even if it’s there already. Can you please assist me? The script is as follows:<\/p>\n
NOTE:This is only part of the script. The first part checks to see if the file is present and, if not, creates it.<\/p>\n
Get-ChildItem “C:\\users$($env:USERNAME)\\appdata\\LocalLow\\Sun\\Java\\Deployment\\security\\exception.sites” | Thanx<\/p>\n OregonSteve<\/p>\n “Never never doubt what nobody is sure about.” -Willy Wonka<\/p>","upvoteCount":1,"answerCount":13,"datePublished":"2018-06-14T14:02:46.000Z","author":{"@type":"Person","name":"stevesmothers2","url":"https://community.spiceworks.com/u/stevesmothers2"},"suggestedAnswer":[{"@type":"Answer","text":" Hi- I’m trying to get a script to work that will add multiple lines to a text file if they don’t already exist. I’ve got the script working to add the content, but for some reason it keeps adding the content even if it’s there already. Can you please assist me? The script is as follows:<\/p>\n NOTE:This is only part of the script. The first part checks to see if the file is present and, if not, creates it.<\/p>\n Get-ChildItem “C:\\users$($env:USERNAME)\\appdata\\LocalLow\\Sun\\Java\\Deployment\\security\\exception.sites” | Thanx<\/p>\n OregonSteve<\/p>\n “Never never doubt what nobody is sure about.” -Willy Wonka<\/p>","upvoteCount":1,"datePublished":"2018-06-14T14:02:47.000Z","url":"https://community.spiceworks.com/t/add-content-if-not-exist/656979/1","author":{"@type":"Person","name":"stevesmothers2","url":"https://community.spiceworks.com/u/stevesmothers2"}},{"@type":"Answer","text":" If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>
\nWhere{!(Select-String -SimpleMatch \" https://site1.comr<\/code>nhttps://site2.com
r<\/code>nhttps://site3.com<\/a> \" -Path $.fullname -Quiet)} |
\nForEach{
\n$Path = $<\/em>.FullName
\n\" https://site1.comr<\/code>nhttps://site2.com
r<\/code>nhttps://site3.com<\/a> \" https://lmdev.4j.lane.edu<\/a>%60r%60nhttps://lmprod.4j.lane.edu%60r%60nhttps://lmrkda.c21u.velocitycloud.net%60r%60nhttps://lmrkpa.c21u.velocitycloud.net%22,(Get-Content $Path)|Set-Content $Path
\n}<\/p>\n
\nWhere{!(Select-String -SimpleMatch \" https://site1.comr<\/code>nhttps://site2.com
r<\/code>nhttps://site3.com<\/a> \" -Path $.fullname -Quiet)} |
\nForEach{
\n$Path = $<\/em>.FullName
\n\" https://site1.comr<\/code>nhttps://site2.com
r<\/code>nhttps://site3.com<\/a> \" https://lmdev.4j.lane.edu<\/a>%60r%60nhttps://lmprod.4j.lane.edu%60r%60nhttps://lmrkda.c21u.velocitycloud.net%60r%60nhttps://lmrkpa.c21u.velocitycloud.net%22,(Get-Content $Path)|Set-Content $Path
\n}<\/p>\n