title: Why can't I access class variables in function in Powershell 5?
body: <p>I'm trying to define a class in Powershell v5 and I can't access variables from within class functions.</p>
  
  <p>Ex.</p>
  
  <pre><code>PS C:\&gt; class Foo{
            $bar = 'foobar'
            mymethod(){
              $bar + '123'
            }
          }
  PS C:\&gt; [Foo]::new().mymethod()
  PS C:\&gt; At line:4 char:11
          +           $bar + '123'
          Variable is not assigned in the method.
  </code></pre>