title: Unable to create task in task scheduler using PowerShell
body: <p>I am trying to create a task in task scheduler using Powershell.</p>
  
  <pre>$PSVersionTable.PSVersion
  
  Major  Minor  Build  Revision
  -----  -----  -----  --------
  3      0      -1     -1</pre>
  
  <p>OS: Windows Server 2012</p>
  
  <p>Here's the script for reference:</p>
  
  <pre><code>Set-Location c:\automation
  
  # Remove IP of host on which this script is going to run
  $hostname = hostname
  $private_ip = (Test-Connection $hostname -count 1).IPv4Address.IPAddressToString
  (get-content .\sch_task_action.conf) | foreach-object {$_ -replace "and not net $private_ip", ""} | set-content .\sch_task_action_final.conf
  
  # Create task schedular
  $sch_task_action = Get-Content c:\automation\sch_task_action_final.conf -Raw
  $sch_task_principal = New-ScheduledTaskPrincipal -UserId "LOCALSERVICE" -LogonType ServiceAccount
  $sch_task_settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Days 7)
  $trigger = New-ScheduledTaskTrigger -AtStartup
  
  Register-ScheduledTask -Action $sch_task_action -Trigger $trigger -Principal $sch_task_principal -Settings $sch_task_settings -TaskName "Monitoring"
  </code></pre>
  
  <p>Content of <code>sch_task_action.conf</code>:</p>
  
  <pre><code>New-ScheduledTaskAction -Execute c:\windump\windump.exe –Argument "-i 1 -q -w e:\network-dump\Network-Traces.txt -n -C 100 -W 100 -U -n ip and not net 125.14.93.7 and not net 10.0.2.4"
  </code></pre>
  
  <p>When I try to run the PowerShell script, I'm getting the following error:</p>
  
  <pre>Register-ScheduledTask : Cannot process argument transformation on parameter 'Action'.
  Cannot convert value "New-ScheduledTaskAction -Execute C:\windump\windump.exe –Argument
  "-i 1 -q -w E:\network-dump\Network-Traces.txt -n -C 100 -W 100 -U -n ip and not net
  125.14.93.7 and not net 10.0.2.4"
  " to type "Microsoft.Management.Infrastructure.CimInstance[]".
  Error: "Cannot convert value "New-ScheduledTaskAction -Execute C:\windump\windump.exe
  –Argument "-i 1 -q -w E:\network-dump\Network-Traces.txt -n -C 100 -W 100 -U -n ip and
  not net 125.14.93.7 and not net 10.0.2.4"
  " to type "Microsoft.Management.Infrastructure.CimInstance".
  Error: "Specified argument was out of the range of valid values.
  Parameter name: className""
  At C:\Automation\windump\win_dump.ps1:26 char:32
  + Register-ScheduledTask -Action $sch_task_action -Trigger $trigger -Principal $sc ...
  +                                ~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidData: (:) [Register-ScheduledTask], ParameterBindingArgumentTransformationException
      + FullyQualifiedErrorId : ParameterArgumentTransformationError,Register-ScheduledTask</pre>
  
  <p>Note: In the script, if I pass the content of <code>sch_task_action_final.conf</code> (which has the selected IP removed) directly to the variable (as shown below) without reading the file using <code>Get-Content</code>, then the script works fine and task gets created in the scheduler.</p>
  
  <pre><code>$sch_task_action = New-ScheduledTaskAction -Execute c:\windump\windump.exe –Argument "-i 1 -q -w e:\network-dump\Network-Traces.txt -n -C 100 -W 100 -U -n ip and not net 125.14.93.7"
  </code></pre>
  
  <p>I've spent few hours trying to figure out by searching online but to no avail.</p>