0

i wanted to replace what ever lines come between

<? and <Arguments>

and also

</Arguments> and </Task> 

via powershell and regex

here's the entire string

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.1" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Author>administrator</Author>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <Enabled>true</Enabled>
      <StartBoundary>2013-03-13T00:34:00</StartBoundary>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Settings>
    <Enabled>true</Enabled>
    <ExecutionTimeLimit>PT259200S</ExecutionTimeLimit>
    <Hidden>false</Hidden>
    <WakeToRun>false</WakeToRun>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <Priority>5</Priority>
    <IdleSettings>
      <Duration>PT600S</Duration>
      <WaitTimeout>PT3600S</WaitTimeout>
      <StopOnIdleEnd>false</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
  </Settings>
  <Principals>
    <Principal id="Author">
      <RunLevel>HighestAvailable</RunLevel>
      <UserId>SMETEST\Administrator</UserId>
      <LogonType>InteractiveTokenOrPassword</LogonType>
    </Principal>
  </Principals>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Program Files\NetApp\SnapManager for Exchange\SMEJobLauncher.exe</Command>
      <Arguments>new-backup -Server 'SME' -ManagementGroup 'Standard' -RetainBackups 8 -RetainUtmBackups 20 -Sto
rageGroup 'testingDB1' -UseMountPoint  -MountPointDir 'C:\Program Files\MgrMountPoi
nt' -RemoteAdditionalCopyBackup $False</Arguments>
      <WorkingDirectory>C:\Program Files\NetApp\SnapManager for Exchange\</WorkingDirectory>
    </Exec>
  </Actions>
</Task>

i just want the output to look like

new-backup -Server 'SME' -ManagementGroup 'Standard' -RetainBackups 8 -RetainUtmBackups 20 -StorageGroup 'testingDB1' -UseMountPoint  -MountPointDir 'C:\Program Files\MgrMountPoint' -RemoteAdditionalCopyBackup $False

1 Answer 1

5

Instead of wasting time on regex with XML - use Select-Xml and XPath:

Select-Xml -Path .\Test.xml -Namespace @{ 
    t = "http://schemas.microsoft.com/windows/2004/02/mit/task" 
} -XPath //t:Arguments | foreach { $_.node.InnerText -replace '\n' }

I've remove newlines, assuming that's what you want.

Sign up to request clarification or add additional context in comments.

2 Comments

hello, i want to remove lines in between <? and <Arguments> and also </Arguments> and </Task> in xml so that my output looks like "new-backup -Server 'SME' -ManagementGroup 'Standard' -RetainBackups 8 -RetainUtmBackups 20 -StorageGroup 'testingDB1' -UseMountPoint -MountPointDir 'C:\Program Files\MgrMountPoint' -RemoteAdditionalCopyBackup $False " for that only i selected the xml and out in a variable to treat it like a string
@PowerShell Just replace -Path .\Test.xml with -Content $string if you want to process a string instead of a file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.