title: Enter PSSession with Variable for ComputerName
body: <p>I am trying to enter a PSSession using <code>-Computername $Server</code> which was previously defined, but I can't seem to get this to work.</p>
  
  <p>I have tried single, double, and no quotes around the variable at all. What am I doing wrong?</p>
  
  <pre><code>$Servers = Import-Csv "C:\Users\username\Desktop\DNS.csv"
  $secpass = ConvertTo-SecureString 'mypassword' -AsPlainText -Force
  $myCred = New-Object System.Management.Automation.PSCredential("username", $secpass)
  
  foreach ($Object in $Servers) {
      $Server = $Object.Name
  
      Enter-PSSession -ComputerName "$Server" -Credential $myCred
      sl HKLM:\SYSTEM\CurrentControlSet\Services\NetBT\Parameters
      Invoke-Command -ScriptBlock {Get-Item -Path HKLM:\SYSTEM\CurrentControlSet\Services\NetBT\Parameters}
      Exit-PSSession
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/dkMGD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dkMGD.png" alt="enter image description here"></a></p>