find and replace wildcard

Welcome Forums General PowerShell Q&A find and replace wildcard

This topic contains 5 replies, has 2 voices, and was last updated by

 
Participant
10 months, 3 weeks ago.

  • Author
    Posts
  • #103604

    Participant
    Topics: 22
    Replies: 47
    Points: 50
    Rank: Member

    edit: how do I display the two arrow characters on the comma and period keys in this forum? it's getting edited out as 'code'

    i'm trying to edit content in a scheduled task. the task xml contains this line

    2018-06-29T23:59:00

    i'm trying to replace the "2018-06-29T" part, but the '2018-06-29' part could be anything, so I need a wildcard.

    $content = (Get-Content $task)
    $newcontent= $content -Replace "*T",$new
    $newcontent

    $newcontent is still $content, so I don't think it's finding the text to replace, possibly because of the arrow characters in the text, possibly because of the wildcard. help?

  • #103606

    Participant
    Topics: 1
    Replies: 1330
    Points: 1,674
    Helping Hand
    Rank: Community Hero

    How familiar are you with the concept of regular expressions in general and in Powershell in particular? It is used when you use comparison operators like -match and -replace.
    That would lead to a command like this:

    $newcontent= $content -Replace ".*T",$new

    to "fix" your code.
    On the other hand I'm pretty sure there are probably better ways to manipulate a scheduled task than using string acrobatics. 😉 You might show some more of your code. We might help you with this.

    • #103619

      Participant
      Topics: 22
      Replies: 47
      Points: 50
      Rank: Member

      testing:

      2018-06-30T
  • #103622

    Participant
    Topics: 22
    Replies: 47
    Points: 50
    Rank: Member

    so the text I need to replace, and the text I need to use to replace it, both contain characters that I can't display in this forum because the forum thinks it's code. and I can't upload a screenshot. it's the left and right arrow characters above the comma and period on the keyboard.

  • #103624

    Participant
    Topics: 22
    Replies: 47
    Points: 50
    Rank: Member

    the text I need to replace: "('less than' symbol)StartBoundary('greater than' symbol)2018-06-18T"

  • #103627

    Participant
    Topics: 22
    Replies: 47
    Points: 50
    Rank: Member

    I went the XML route, and it replaces the text I want, but apparently that doesn't actually affect the scheduled task anyway. i'm trying to change the Date in "startboundary" without changing the time.

     $Date = (get-date -Format o).split('T')[0]
     $xml = [xml](Get-Content $task)
     $current = $xml.task.Triggers.TimeTrigger.StartBoundary
     $currenttime = $current.split("T")[1]
     $new = $date + "T" + $currenttime
     $xml.task.triggers.timetrigger.StartBoundary = $new
     $xml.Save($task.FullName)
    

    that code successfully modifies the XML of the task just like I want, but the trigger remains unchanged in the task scheduler GUI.

The topic ‘find and replace wildcard’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort