0

我想替换之间的任何线条

<? and <Arguments>

并且

</Arguments> and </Task> 

通过 powershell 和正则表达式

这是整个字符串

<?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>

我只希望输出看起来像

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

1 回答 1

5

与其在使用 XML 的正则表达式上浪费时间,不如使用 Select-Xml 和 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' }

假设这是您想要的,我已经删除了换行符。

于 2013-03-15T08:08:38.310 回答