title: PowerShell v5 class method - problems
body: <p>Playing with the new class function in PowerShell v5, and I'm trying to get my head around if we can put methods into classes.</p>
  
  <p>I've tried the below and played about with it for a bit, but haven't been having luck. </p>
  
  
  
  <pre class="lang-powershell prettyprint-override"><code>class Server {
  
      [string]$computerName = "192.168.0.200"
      [bool]$ping = (Test-Connection -ComputerName $computerName).count
  
  }
  
  $1 = [server]::new()
  $1.computerName = "blah"
  </code></pre>
  
  <p>I've tried with manually entering a computer name via setting the property, but then I assumed you'd need it at object creation</p>
  
  <pre class="lang-powershell prettyprint-override"><code>$1 = [server]::new($computerName = "192.168.0.200")
  </code></pre>
  
  <p>Exceptions I'm getting are</p>
  
  <pre class="lang-powershell prettyprint-override"><code>[ERROR] Exception calling ".ctor" with "0" argument(s): "Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the 
  [ERROR] command again."
  [ERROR] At D:\Google Drive\Projects\VSPowerShell\DiscoveryFramework\DiscoveryFramework\DiscoveryFramework\class.ps1:12 char:1
  [ERROR] + $1 = [server]::new()
  [ERROR] + ~~~~~~~~~~~~~~~~~~~~
  [ERROR]     + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
  [ERROR]     + FullyQualifiedErrorId : ParameterBindingValidationException
  [ERROR]  
  [DBG]: PS C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE&gt; 
  [DBG]: PS C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE&gt; $1
  Server
  [DBG]: PS C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE&gt; $1.gettype()
  Server
  </code></pre>
  
  <p>Full exception link from $error is on <a href="http://pastebin.com/WtxfYzb5" rel="nofollow">http://pastebin.com/WtxfYzb5</a></p>
  
  <hr>
  
  <p><strong>Got a bit further used $this.prop, but you cant initiate the constructor with your own parameters.</strong></p>
  
  <pre class="lang-powershell prettyprint-override"><code>PS path:\&gt; class Server {
  
      [string]$computerName = "192.168.0.200"
      [bool]$ping = (Test-Connection -ComputerName $this.computerName).count
  
  }
  
  PS path:\&gt; 
  PS path:\&gt; $var = [server]::new()
  
  PS path:\&gt; $var
  
  computerName  ping
  ------------  ----
  192.168.0.200 True
  </code></pre>