title: Trim in a ForEach query
body: <p>In my homelab I try to automate scheduled tasks by using PowerShell. I use [System.Collections.Generic.List[String] to collegt a list of all switches for the execution. But I cannot manage to remove the <strong>`</strong> in the last line of my output? Anyone an idea how to solve this issue?</p>
  <pre><code>-AtLogOn `
  -AtStartup `
  -Daily `
  -DaysInterval 3 `
  -DaysOfWeek Sunday, Monday `
  -Once `
  -RandomDelay (new-Timespan -Minutes 15) `
  -RepetitionDuration (new-Timespan -Minutes 15) `
  -RepetitionInterval (new-Timespan -Minutes 15) `
  -Weekly `
  -WeeksInterval 2 `
  -At 3am `
  </code></pre>
  <p>Here is the code to generate the output:</p>
  <pre><code>$xml = [xml]@'
  &lt;Test&gt;
      &lt;App TaskName = &quot;LAB&quot; Active = &quot;True&quot; &gt;
        &lt;Task Name = &quot;ScheduledTask&quot; Active = &quot;True&quot; Order = &quot;1&quot; Description = &quot;&quot; TaskName = &quot;&quot; Execute = &quot;Powershell.exe&quot; Argument = &quot;-command &amp;amp; D:\ProgramFiles\Tools\Test.ps1 -Application&quot; WorkingDirectory = &quot;&quot; AtLogOn = &quot;1&quot; AtStartup = &quot;1&quot; Daily = &quot;1&quot; DaysInterval = &quot;3&quot; DaysOfWeek = &quot;Sunday, Monday&quot; Once = &quot;1&quot; RandomDelay = &quot;(new-Timespan -Minutes 15)&quot; RepetitionDuration = &quot;(new-Timespan -Minutes 15)&quot; RepetitionInterval = &quot;(new-Timespan -Minutes 15)&quot; Weekly = &quot;1&quot; WeeksInterval = &quot;2&quot; At = &quot;3am&quot; /&gt;
      &lt;/App&gt;
  &lt;/Test&gt;
  '@
  
  
  If($($xml.Test.App.Active) -eq &quot;True&quot;) {
    ForEach($ActiveTask in $xml.Test.App.Task | Sort-Object Order | Where-Object { $_.Active -eq &quot;True&quot; }){
      Switch($ActiveTask.Name){
        ScheduledTask {
          $TriggerParams = [System.Collections.Generic.List[String]]@()
          If ($TriggerParams.Count -gt 0) { $TriggerParams.Clear() }
          If ($ActiveTask.AtLogOn -eq &quot;1&quot;){
            $TriggerParams.Add($(&quot;-&quot; + &quot;AtLogOn&quot; + ' `').Trim())
          }
          If ($ActiveTask.AtStartup -eq &quot;1&quot;){
            $TriggerParams.Add($(&quot;-&quot; + &quot;AtStartup&quot; + ' `').Trim())
          }
          If ($ActiveTask.Daily -eq &quot;1&quot;){
            $TriggerParams.Add($(&quot;-&quot; + &quot;Daily&quot; + ' `').Trim())
          }
          If ($ActiveTask.DaysInterval -ne &quot;&quot;){
            $TriggerParams.Add($(&quot;-&quot; + &quot;DaysInterval &quot; + $ActiveTask.DaysInterval + ' `').Trim())
          }
          If ($ActiveTask.DaysOfWeek -ne &quot;&quot;){
            $TriggerParams.Add($(&quot;-&quot; + &quot;DaysOfWeek &quot; + $ActiveTask.DaysOfWeek + ' `').Trim())
          }
          If ($ActiveTask.Once -eq &quot;1&quot;){
            $TriggerParams.Add($(&quot;-&quot; + &quot;Once&quot; + ' `').Trim())
          }
          If ($ActiveTask.RandomDelay -ne &quot;&quot;){
            $TriggerParams.Add($(&quot;-&quot; + &quot;RandomDelay &quot; + $ActiveTask.RandomDelay + ' `').Trim())
          }
          If ($ActiveTask.RepetitionDuration -ne &quot;&quot;){
            $TriggerParams.Add($(&quot;-&quot; + &quot;RepetitionDuration &quot; + $ActiveTask.RepetitionDuration + ' `').Trim())
          }
          If ($ActiveTask.RepetitionInterval -ne &quot;&quot;){
            $TriggerParams.Add($(&quot;-&quot; + &quot;RepetitionInterval &quot; + $ActiveTask.RepetitionInterval + ' `').Trim())
          }
          If ($ActiveTask.Weekly -eq &quot;1&quot;){
            $TriggerParams.Add($(&quot;-&quot; + &quot;Weekly&quot; + ' `').Trim())
          }
          If ($ActiveTask.WeeksInterval -ne &quot;&quot;){
            $TriggerParams.Add($(&quot;-&quot; + &quot;WeeksInterval &quot; + $ActiveTask.WeeksInterval + ' `').Trim())
          }
          If ($ActiveTask.At -ne &quot;&quot;){
            $TriggerParams.Add($(&quot;-&quot; + &quot;At &quot; + $ActiveTask.At + ' `').Trim())
          }
  
          $TriggerParams
          #$TaskTrigger = Invoke-Expression &quot;New-ScheduledTaskTrigger $TriggerParams&quot;
  
        }
      }
    }
  }
  </code></pre>
  <p>Cheers, Cpt</p>