Replacing text that contain :, [ in a file with powershell

So we have recent come across a situation where we need to replace a line of text in a txt file (config file). We have the following PS code, it opens the file, appears to process the command, closes and saves the file (at least the time stamp has updated).
$old = ' "enabled_labs_experiments": [ ],'
$new = ' "enabled_labs_experiments": [ "disable-direct-write" ],'
(Get-Content "C:\Users\Jesse\AppData\Local\Google\Chrome\User Data\Local State – Copy") | ForEach-Object {$_ -replace $old, $new} | Set-Content "C:\Users\Jesse\AppData\Local\Google\Chrome\User Data\Local State – Copy"
We do not need the variables but we did it that way instead of inline so that we could more easily see what we are changing.
Basically nothing gets updated in this file. There are other places in this same file that we can update the code and it works perfectly so I have a feeling that it has to do with the [ ] or the : or some other character that PS uses. Unfortunately we cannot
omit the : or the [ ] due to that being exactly what we need to change in the file.
The following works perfectly
$old="USA"
$new="en"
(Get-Content "C:\Users\Jesse\AppData\Local\Google\Chrome\User Data\Local State") | ForEach-Object {$_ -replace $old, $new} | Set-Content "C:\Users\Jesse\AppData\Local\Google\Chrome\User Data\Local State"
Any suggestions are greatly appreciated!!

You might be able to make use of [regex]::Escape() to automatically make those characters literal when being read in regex by escaping them.
Not tested:
$old = [regex]::Escape(' "enabled_labs_experiments": [ ],')
$new = ' "enabled_labs_experiments": [ "disable-direct-write" ],'
(Get-Content "C:\Users\Jesse\AppData\Local\Google\Chrome\User Data\Local State – Copy") | ForEach-Object {
$_ -replace $old, $new
} | Set-Content "C:\Users\Jesse\AppData\Local\Google\Chrome\User Data\Local State – Copy"
Boe Prox
Blog |
Twitter
PoshWSUS |
PoshPAIG | PoshChat |
PoshEventUI
PowerShell Deep Dives Book

Similar Messages

  • I'm a new MAC user and I'm trying to transfer my iTunes music files to my Mac, however when I attach the external drive that contains the music files, they aren't visible on the MAC (but they are visible on my old PC).  How do I get my music loaded?

    I'm a new MAC user and I'm trying to transfer my iTunes music files to my Mac, however when I attach the external drive that contains the music files, the music files aren't visible on the MAC (but they are visible on my old PC).  How do I get my music transferred?  I have already exported the purchased music from the iTunes library, but I have thousands of songs from my private CD collection that I had previously loaded through iTunes.

    Paragon Software has the most reliable NTFS driver for Mac
    tips on importing and organizing, transferring from Windows etc
    http://www.apple.com/support/itunes
    http://www.ilounge.com

  • How to combine swm file with powershell

    hi,I get strucked in "combining swm file with powershell",
    there are two swm file in my volume D ,when i use the command "Export-WindowsImage -SourceImagePath D:\t.swm  -SplitImageFilePattern D:\t*.swm -DestinationImagePath G:\install.wim -SourceIndex 1"
    it told me:"file exited,you can't create this file".
    but when i used dism /apply-image command it works well.
    i tried the command "export-windowsimage",but not succeed.

    no,do you have any solution?
    I think ,er,it may be a bug .
    if you try the expand  of "expand-windowsimage " in powershell.you will find it still not work

  • Flattening a PDF that contains an XML file

    Hi I am hoping someone can help me.
    We have a PDF document that contains an XML form. We are starting to utilize DocuSign software to electronically sign and route our forms. The problem is that this form cannot be converted in the DocuSign portal. We need a way to flatten the software once it has been completed and all information has been input into the form and sent to us by a faculty member. I have downloaded a couple of different JavaScript add ons and have tried them. One doesn't seem to do anything the other one UVSAR_selectiveFlatten.js attempts to flatten the form but then quits and pops up the message "Security settings or digital signatures in this file prevent flattening."
    When I look at the security settings under properties for the form it says "No Security" in the drop down box and there are no signatures in the form. I am attempting all of this on a blank form.
    Flattening or printing to PDF works ok on a PC but we have a few Mac users and that is where our problems are coming in. The only option to print to PDF is the little drop down box in the bottom left corner of the print dialog box that says save as PDF. When we try this it pops up the message, "Saving a PDF file when printing is not supported. Instead, choose File > Save." File>Save just saves a copy with all of the XML code, etc.
    The only other option we have found is to save the file as an image but this then breaks the file into 3 pages. We also don't want to print the form and then have to rescan it back in.
    Does anyone have any suggestions on what we could do to flatten the image so that it could be easily uploaded to DocuSign.
    A link to the form is here: http://rgs.usu.edu/spo/files/uploads/forms/SP-01.pdf
    Any help or advice that you may have to offer will be greatly appreciated.

    Ok, this is an XML/XFA/Designer form.
    You cannot use JavaScript designed for Acrobat forms (Acroforms). I suspect that is the problem. You must develop JavaScript using the Designer JavaScript object model. Not sure if that even supports flattening, since it isn't really a PDF at all with all that XML stuff.

  • Issue with site template that contains a document library with a lookup column to another list

    I have a document library called Proposals with a lookup column in the same site called Document Categories (multiple values allowed).  It points to a list called document categories.  I have several sample documents in the Proposal Library that
    contain valid document categories.  When I save the site as a template and instantiate it, everything is fine.  However, when I remove the sample documents from the Proposal library and rebuild the site template, I can't get the  template to
    create another site.  I get an error Unable To Open Lookup List.
    I don't understand why I can instantiate a site from the template when there's sample data, but not when the document library containing the lookup column is empty.
    Does SharePoint 2010 site template support lookup columns?
    Why would it make a difference if the library is empty?
    Thanks

    Hi,
    According to your description, my understanding is that the error occurred when you created a site from the template with no files in the document library.
    I tested the same scenario per your post, and I can create a site from the template with no files in the document library with no errors.
    To solve this issue, I recommend to verify the things below:
    Did you save the site as a template with Include Content checked? If yes, I recommend to test if it works when saving the site as a template with Include Content unchecked.
    Test the same scenario with a new site to narrow the issue scope.
    I also recommend to check the event log and ULS log to see if anything unexpected occurred.
    To check event log, click the Start button and type “Event Viewer” in the Search box.
    For SharePoint 2010, by default, ULS log is at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS.
    You can check the ULS log by the methods here:
    http://blogs.msdn.com/b/opal/archive/2009/12/22/uls-viewer-for-sharepoint-2010-troubleshooting.aspx
    http://msdn.microsoft.com/en-us/library/gg193966(v=office.14).aspx
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • Copy and paste text that contains 1/2

    '''ALL''' text from any Firefox webpage that contains the character "1/2"… when pasted into a word processing document (Appleworks v. 6.2.9, in this case) inserts MULTIPLE 1/2 spaces.
    All individual text characters are thus separated by two (2) 1/2 spaces and word spacings are three (3) 1/2 spaces.

    The way to do it in previous versions (at least in version 9) was by
    right-clicking the field and selecting Duplicate. This created copies of the
    fields in the same place as the original, but also with the same name, and
    therefore the same value. You will need to rename them if you want them to
    be unique. If you need to do this very often, a script might be a better
    solution.

  • Copy Paste text that contains cross-references destroys them

    Hi folks,
    Using ID CS 5.5.
    Working on a book file that contains ca. 30 documents.
    Copying (or cutting) and pasting any text that includes a cross-reference to another document in the book breaks the cross-reference.  This happens even if pasting directly back into the same location.  Cross-references to locations within the same document are not affected.
    Is this a known issue?  Is there some kind of work around?  It seems like too big a bug to not already be solved.
    Thanks.
    EDIT: working on this further, I realize it's actually much, much worse than I've described.  Copying and pasting crossrefs across documents can sometimes destroy all cross refs in all documents in the book.

    painstakingly change each setting on the control tab.
    Painstakingly is your only option other than using something like this: http://www.xmedit.com/
    -DH

  • Sublime Text 2 won't open files with double click

    Hi, this is my first time asking for something.
    Well, i've been using Scribes, but sometimes i need tabs in my text editor, so i installed Sublime Text 2.
    The problem is that i can't open files with double click, i need to use "subl filename" and that it's not funny :S
    If i double click a file ST2 opens, but with a tab named "file" and without content.
    Is there a fix for that?
    My Arch installation (if is neccesary):
    Arch x86_64
    Openbox (stand-alone)
    PCManFM
    P.D: sorry for my english D:

    the reason seems to be a broken desktop file.  `/usr/share/applications/sublime-text.desktop` says `Exec=subl %U`, but it should be `%f`. Also the Aur package does not provide a `subl` symlink so you should create one.

  • Trying to delete a file with Powershell script ran by a service but issues with uac

    I'm having issues with a script that will delete a file on the C-Drive of a server. the script looks like this:
    param(
    [Parameter(Mandatory=$true)][string]$hostname
    $StrFileName = "C:\Program Files\NSClient++\nsclient.log"
    $LogLocal="c:\Nagios\naf_delete_nscp_log_file.log"
    $Date = Get-Date -Format "yyyy-MM-dd hh:mm:ss"
    "$date : NSClient logfile deletion requested on $hostname" | Out-File -filepath $LogLocal -Append
    If (Test-Path "$strFileName"){
    Remove-Item $strFileName -Force
    $Date = Get-Date -Format "yyyy-MM-dd hh:mm:ss"
    "$date : NSClient logfile deleted on $hostname" | Out-File -filepath $LogLocal -Append
    The script is initiated from a Nagios quick action which will use nrpe to pass the host as parameter and make the nscp service, which runs as local system, run it. It works perfectly on servers that have no uac enabled, but I can't get it to work on servers
    with uac. I've tried numerous options, but none seem to work. Any tips or advice to get this working with Powershell v2 code on servers with uac enabled is highly appreciated.
    Thanks.
    Willem

    Hi Willem,
    one thing to note: I don't see why your script itself has a hostname parameter.
    One way around UAC has always been the Windows Task Scheduler. If you register a task as System run and triggered by an event, you can simply call the event locally (which doesn't require admin permissions) and it will perform the task.
    I don't know how your Nagios construct works and the script by itself doesn't make much sense. If you want advice on how to do this without resorting to tasks, I'd need to know more about the system you are using.
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • Rendering text that contains old-style HTML character entities, e.g. ü

    The large text-corpus I'm working with was produced before the days of widespread Unicode support, and it contains HTML character entities instead of unicode codepoints, e.g. ü for ü [u-umlaut].
    I can iterate through every text column in the ArrayCollections that I'm using for dataProviders to the DataGrid, and replace these entities with their unicode counterparts before the provider is assigned to the grid. But is there already a mechanism in place in Flex to render character entities in the DataGrid? Is there a ready-made ItemRenderer that can do this?
    Thanks

    DrClap wrote:
    So your example looks like this?
    <someNode>der fuchs springt &#252;ber den stein</someNode>
    now I feel stupid :-) Yes, that's correct.
    And you're actually getting an EntityReference node in your Document? I find that rather strange, since the documentation for EntityReference says
    Note that character references and references to predefined entities are considered to be expanded by the HTML or XML processor so that characters are represented by their Unicode equivalent rather than by an entity reference.
    Exactly!
    Because what you have there is a character reference. Is there something else in the document, a DTD for example, which might be interfering with that?No, just an ordinary XML header:
    <?xml version="1.0" encoding="UTF-8"?> ...If it helps, I can also post the complete document I am receiving.

  • How can I replace a 3D object in AE file with another 3D object?

    I am an AE novice, but an expert in many Adobe products, as well as a quick learner. I have purchased an AE file from videohive.net for a Christmas eCard we are producing for my agency. The file has a Christmas snow globe with a 3D Christmas tree inside it. I want to replace the Christmas tree object with a different object that doesn't yet exist. I want to create an object in Illustrator and extrude it, and hopefully import it into my AE file. Is this possible/difficult?

    There's quite a lot of content at Videohive that might be the project you're talking about.  Can you provide a link to it?
    Many Videohive projects contain pre-rendered 3D elements from other applications that are not easily replaced.  It's impossible to say in this instance without seeing the project you're referring to.

  • I reset my MacBook pro and a symbol pops up that looks like a file with a ? In the middle of it. Does anyone know what this means?

    How do I fix this?

    What does "reset" mean?  I'm going to assume that means you restarted it somehow, but if you meant something else, please say so.
    The flashing question mark means no bootable system could be found.  Hold down command-R at startup to enter recovery mode, then repair the hard drive with Disk Utility.  If it succeeds, you may still need to reinstall the system, as some files may be corrupt.  You can install right over the existing system, but it would be wise to be sure you have backups beforehand in case something goes wrong.
    If repairs cannot be made, you will need to try another utility,mike DiskWarrior, or just erase the hard drive and reinstall from scratch.
    If the hard drive does not show up in Disk Utility, it has probably dies and will need to be replaced.

  • I've got a file that is getting auto-created on my desktop, that is a .textClipping file with a very long series of numbers and letters as the filename (and of course, as the clipping as well).  Is there any way to tell what is creating this file?

    As the title states, I've got a .textClipping file that keeps getting created on my desktop when I log in.  The file looks similar to: "6bc29bf81b634b3293da5e858930e06a88adf182.textClipping".  I'm trying to figure out what is creating this file.  Any suggestions?
    Thanks in advance.

    Login items:
    SophosUIServer
    textexpanderd (Text Expander 2.x - possibly the culprit?)
    TotalFinder
    Remote Wonder Driver
    Lockdown
    macfusionAgent
    Most of these I've had installed for a year or more.  TotalFinder and Text Expander may be relatively new.

  • How do I merge two accounts into one account that contains all the files from both?

    When I was running my MacBook Pro under Snow Leopard, I had one account for business that was encripted and another account that was unencripted for personal.  Now, under Lion, the whole disc gets encripted so I don't really need two acounts.  How do I merge the accounts together into one account and retain all the files from both?
    Thanks,
    Dave

    Somethinkg like these?

  • How do I open a .nrl extension in firefox, currently it returns a string of text instead of opening the file with the default program.

    When I click on a .nrl file extension (belongs to Autonomy I-Manage Software) it returns a string of code (what is in the shortcut link) instead of following the link and returning the document. Is there a way to tell Forefox connect to the document that the shortcut is linked to? The .nrl file extension belongs to a piece of software called FileSite (document management system).

    '''Adding download actions''' is the relevant section of that article for your situation.
    Is the *.nrl file on a website or already saved to your PC?
    If it is on a website, the server may not be sending the appropriate Mime-Type telling Firefox how that file is to be handled - ''"Content-Disposition"''.
    Can you give us the URL of the webpage where you have this problem? <br />
    So we can see first hand what the issue is.

Maybe you are looking for

  • Error message while loading XML parser into db

    I get the following error message while loading xmlparserv2.jar ORA-29534 referenced object SYSTEM.oracle/xml/parser/v2/XMLNOde could not be resolved ORA-29545: badly formed class: java.lang.NullPointerException using XSU111 package

  • IOS - Create Event from Messages in Calendar doesn't observe default Alert settings

    I have discovered a bug in the iOS Calendar app. If one gets a text message with a time and uses the underlined link (in Messages) to "Create Event," the newly created calendar item (Event) does not set the alert as defined in Calendar settings. For

  • Can Java3D (canvas3D) be displayed at the same time on 2 users?

    For example, both Ann and Bob are doing the same project on 3D Object. Can Ann's change to the Canvas3D be saw by Bob dynamically?

  • Serious merge error

    I am doing this from within Jdeveloper 9034 with a 9i SCM version 4.0.12.91.9. Strict locking is not enabled. A file is checked out by user A. User B checks the same one out, modifies it, and checks it in. When user A checks this file in, he is promp

  • Avoid Creating a Blank Page in the PDF Output for conditional request

    Hello BI Masters I have a Conditional request on my Last page of the data it checks the number of rows in the first page then it prints the excess rows in the last page and everything is working fine but when i use the conditional request its generat