Reputation: 2051
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
Upvotes: 0
Views: 379
Reputation: 8650
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.
Upvotes: 5