title: 'Session' Parameter is null or empty in PowerShell script
body: <p>I'm very new to PowerShell (forgive my ignorance) and am trying to install a program remotely on multiple computers on my domain. Currently, I'm just trying to get it to work on one computer. The script below was found online and adapted for my needs. Yesterday it worked, but today it's complaining about the session parameter. </p>
  
  <p>I don't fully understand "sessions", but I have ensured on the client machine that the winrm service is running and I have invoked <code>Enable-PSRemoting -force</code>.</p>
  
  <p>Here's the script:</p>
  
  <pre><code>$computers = Get-Content "c:\tmpPS\computers.txt"
  $rs = Get-PSSession
  Get-PSSession | Get-Member
  ######
  ## Functions
  ################
  
  foreach ($comp in $computers)
  {
      Write-Host "should work with $comp"
  }
  
  PushMSI
  RemoteConnect
  InstallMSI
  
  Function PushMSI {
   Write-Host "------------------------------------------------"
   Write-Host "This will copy the MSI file from localhost c:\tmpPS\"
   write-Host "------------------------------------------------"
   Write-Host ""
   Write-Host ""
   foreach ($comp in $computers)
  {
     Copy-Item -path "c:\tmpPS\clientInstall.msi" -Destination \\$comp\c$\tmpPS
  
  }
  }
  
  Function RemoteConnect
  {
   Write-Host "------------------------------------------------"
   Write-Host "This will establish a PSSession with all computers in c:\temp\computers.txt"
   write-Host "------------------------------------------------"
   Write-Host ""
   Write-Host ""
  Get-Content C:\tmpPS\computers.txt | New-PSSession -ThrottleLimit 50
  }
  
  Function InstallMSI
  {
   Write-Host "------------------------------------------------"
   Write-Host "This will Install UPS Update on all computers with an Established PSSession"
   write-Host "------------------------------------------------"
   Write-Host "After the Install PSSessions will be removed"
   Write-Host ""
  
  Invoke-Command -Session $rs -ScriptBlock {invoke-item "c:\tmpPS\ClientInstall.msi"}
  }
  
  Get-PSSession | Remove-PSSession
  </code></pre>
  
  <p>And here's the output:</p>
  
  <pre><code>PS C:\Users\Me&gt; C:\tmpPS\remoteInstall.ps1
  Get-Member : No object has been specified to the get-member cmdlet.
  At C:\tmpPS\remoteInstall.ps1:3 char:17
  + Get-PSSession | Get-Member
  +                 ~~~~~~~~~~
      + CategoryInfo          : CloseError: (:) [Get-Member], InvalidOperationException
      + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
  
  should work with eSignWin81.informa.local
  ------------------------------------------------
  This will copy the MSI file from localhost c:\tmpPS\
  ------------------------------------------------
  
  
  ------------------------------------------------
  This will establish a PSSession with all computers in c:\temp\computers.txt
  ------------------------------------------------
  
  
  
   Id Name            ComputerName    State         ConfigurationName     Availability
   -- ----            ------------    -----         -----------------     ------------
    6 Session6        eSignWin81.i... Opened        Microsoft.PowerShell     Available
  ------------------------------------------------
  This will Install UPS Update on all computers with an Established PSSession
  ------------------------------------------------
  After the Install PSSessions will be removed
  
  Invoke-Command : Cannot validate argument on parameter 'Session'. The argument is null or empty. Supply an argument that is not null or empty and then try 
  the command again.
  At C:\tmpPS\remoteInstall.ps1:49 char:25
  + Invoke-Command -Session $rs -ScriptBlock {invoke-item "c:\tmpPS\ClientInstall.ms ...
  +                         ~~~
      + CategoryInfo          : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
      + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
  </code></pre>