2013-03-15 58 views
0

串之間的線我就想換成通過PowerShell和正則表達式PowerShell腳本來替換使用正則表達式

<? and <Arguments> 

</Arguments> and </Task> 

之間的線來什麼都

這裏的整個字符串

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

回答

5

而是與XML正則表達式浪費時間 - 使用選擇的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' } 

我已經刪除換行符,假設這是你想要的。

+0

您好,我想刪除<之間行?和和在xml中,以便我的輸出看起來像「新備份服務器SME」 - 管理組「標準」-RetainBackups 8 -RetainUtmBackups 20 - 存儲組'testingDB1' - 使用MountPoint -MountPointDir'C:\ Program Files \ MgrMountPoint」 -RemoteAdditionalCopyBackup $假 「的,只有我選擇了XML和出一個變量,把它像一個字符串 – PowerShell 2013-03-15 08:11:37

+0

@PowerShell只需更換' - 路徑\ Test.xml'與'$ -content如果string'你想要處理一個字符串而不是一個文件。 – 2013-03-15 08:36:33

+0

非常感謝所有工作:) – PowerShell 2013-03-15 08:38:53