title: Invoke-Command with remote session: Cannot validate argument on parameter
body: <p>I wrote a script to restart a few ASP.NET websites on a remote server:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>$computerName = #...
  $password = #...
  $secureStringPassword = ConvertTo-SecureString -AsPlainText -Force -String $password
  $userName = #...
  $credential= New-Object System.Management.Automation.PSCredential ($userName, $secureStringPassword)
  $websiteNames = #..., #..., #...
  
  Get-PSSession -ComputerName $computerName -Credential $credential | Remove-PSSession 
  
  $psSession = New-PSSession -ComputerName $computerName -Credential $credential
  
  Invoke-Command -Session $psSession -ScriptBlock { $websiteNames | foreach{ Stop-Website -Name $_ } }
  Invoke-Command -Session $psSession -ScriptBlock { $websiteNames | foreach{ Start-Website -Name $_ } }
  
  $psSession | Remove-PSSession 
  </code></pre>
  
  <p>For some reasons my <code>Invoke-Command</code> do not run properly, I have the following error message: </p>
  
  <blockquote>
    <p>Cannot validate argument on parameter 'Name'. The argument is null. Provide a valid value for the argument, and then try running the command again.</p>
  </blockquote>
  
  <p>When the commands are run after an <code>Enter-PSSession</code> it works fine within a <code>-ScriptBlock</code> it kinda mess up the <code>-Name</code> parameter, any idea how to fix that up?</p>