title: How to pass an xml element to a scriptBlock when using invoke-command
body: <p>Using PowerShell 3.0, I am using the Invoke-Command cmdlet to pass an xmlElement to a scriptblock. The problem is that I think the scriptBlock is receiving the parameter as an arrayList and not as an xmlElement (actually, I know that the received param is an <code>ArrayList</code> as I logged out <code>$service.GetType()</code> ).</p>
  
  <p>Here is my XMLElement:</p>
  
  <pre><code>&lt;Service&gt;
      &lt;ServiceName&gt;Spooler&lt;/ServiceName&gt;
      &lt;Startup&gt;Disabled&lt;/Startup&gt;
  &lt;/Service&gt;
  </code></pre>
  
  <p>Here is my scriptBlock:</p>
  
  <pre><code>$scptModifyService = {
      param (
          $service
      );
      Set-Service -Name $service.ServiceName -StartupType $service.Startup;
  }
  </code></pre>
  
  <p>Here is my code calling the scriptBlock:</p>
  
  <pre><code>## Modify remote Services:
  foreach($service in $XML.QCSettings.Services.Service) {
      Invoke-Command -ScriptBlock $scptModifyService -ComputerName $ComputerName -ArgumentList $service;
  }
  </code></pre>
  
  <p>From what I understand about the Invoke-Command cmdlet (get-help invoke-command) is that the ArguementList can take an object as input, so I don't think that is is an issue with how I call the scriptblock in the 'foreach' loop above. Hopefully that makes some sense.</p>
  
  <p>Does anyone have any ideas about how capture the param in my scriptblock as an xmlElement and not as an <code>ArrayList</code>?</p>
  
  <p>I have tried several things already (in my scriptblock):</p>
  
  <pre><code>param( $service = [xml]Get-Content args[0] );
  </code></pre>
  
  <p>And other variations on the that code.</p>