title: Calling a function within a function with invoke-command Powershell
body: <p>I am hoping to call a function within a function in invoke-command. It looks like I am not doing this properly. I get "get-group_users" is not recognized error. Everything is in one ps1 script.</p>
  
  <p>Truncated Script:</p>
  
  <pre><code>function get-session {
  $session = New-PSSession -ComputerName $ip -Credential $cred -Auth CredSSP
  $ComputerName = $cred.Replace('\Admin',"")
  $csv = "C:\Scripts\Serverlists\" + $ComputerName + ".txt"
  $subcomps = import-csv $csv | foreach-object {$_.Name}
  
  foreach ($ComputerName in $subcomps)
  {
  $ComputerName
  $xmlWriter.WriteStartElement("Computer",$ComputerName)
  
  Invoke-Command -Session $session -ScriptBlock { (get-groups_users -ComputerName $ComputerName) } -ArgumentList $ComputerName
  
  $xmlWriter.WriteEndElement()
  }
  Remove-PSSession -ComputerName $ip
  }
  
  
  
  $ip = '172.16.24.11'
  $ComputerName = "COMP1"
  $user = '\Admin'
  $cred = $ComputerName + $user
  
  (get-groups_users -ComputerName $ComputerName)
  (get-session -Credential $cred -ComputerName $ip)
  </code></pre>
  
  <p>So, I'm leaving out the <code>get-groups_users</code> function. I can post it if someone thinks it will help explain everything. It is a long one. Also i am leaving out the <code>$xmlwriter</code> definitions.</p>
  
  <p><code>get-groups_users</code> works when it runs on COMP1, but once I enter <code>PSSession</code> and try and use it in invoke-command for the sub comps it doesn't recognize it.</p>
  
  <p>What am I forgetting?</p>