Sample of declare a simple powershell class with a constructor and a simple method


/ Published in: Windows PowerShell
Save to your folder(s)

Sample of declare a simple powershell class with a constructor and a simple method
Show also how to echo strings on console
Thanks to http://www.peterhenell.se/


Copy this code and paste it in your HTML
  1. #Sample of declare a simple powershell class with a constructor and a simple method
  2. #Show also how to echo strings on console
  3. #Thanks to http://www.peterhenell.se/
  4. function ExtendedWebClient ($url,$timeout)
  5. {
  6. $webclient = "" | Select url,timeout
  7. $webclient.url = $url
  8. $webclient.timeout = $timeout
  9.  
  10. $webclient = $webclient | Add-Member ScriptMethod HelloWorld {"Hello world form {0}" -f $this.url} -passThru
  11. $webclient = $webclient | Add-Member ScriptMethod HelloSun {Write-Host ("Hello Sun " + $this.url)} -passThru
  12. $webclient;
  13. }
  14.  
  15. cls
  16. $extclient = ExtendedWebClient "www.myurl.com" 100
  17. $extclient.HelloWorld()
  18. $extclient.HelloSun()
  19. $extclient

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.