title: Powershell function throwing null exception
body: <p>Okay, so I've read up on calling functions and passing parameters in powershell but maybe I'm not understanding something. I am calling a function and passing a couple parameters and everything works fine. It is variable defined within the function that seems to be null when it isn't.</p>
  
  <p>Function:</p>
  
  <pre><code>function get-session {
  $session = New-PSSession -ComputerName $ip -Credential $cred -Auth CredSSP
  $subcomps = 'COMP1'
  foreach ($Computer in $subcomps)
  {
  $Computer
  Invoke-Command -Session $session -ScriptBlock { Get-WmiObject -ComputerName $Computer -Query "SELECT * FROM Win32_Group" }
  }
  Remove-PSSession -ComputerName $ip
  }
  </code></pre>
  
  <p>Script:</p>
  
  <pre><code>$ip = '123.45.67.89'
  $ComputerName = "HOPCOMP"
  $user = '\Admin'
  $cred = $ComputerName + $user
  $ip
  $cred
  (get-session -ComputerName $ip -Credential $cred)
  </code></pre>
  
  <p>When I run this:</p>
  
  <pre><code>Cannot validate argument on parameter 'ComputerName'. The argument is null or empty.
  Supply an argument that is not null or empty and then try the command again.
  + CategoryInfo          : InvalidData: (:) [Get-WmiObject], ParameterBindingValidationException
  + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetWmiObjectCommand
  </code></pre>
  
  <p>Of course, if I change $Computer in in the function Get-WMIObject line to COMP1 everything works great. But, the $Computer write out in the foreach loop writes COMP1 successfully.</p>
  
  <p>What am I missing here?</p>