/ Published in: Windows PowerShell
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/
Show also how to echo strings on console
Thanks to http://www.peterhenell.se/
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#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/ function ExtendedWebClient ($url,$timeout) { $webclient = "" | Select url,timeout $webclient.url = $url $webclient.timeout = $timeout $webclient = $webclient | Add-Member ScriptMethod HelloWorld {"Hello world form {0}" -f $this.url} -passThru $webclient = $webclient | Add-Member ScriptMethod HelloSun {Write-Host ("Hello Sun " + $this.url)} -passThru $webclient; } cls $extclient = ExtendedWebClient "www.myurl.com" 100 $extclient.HelloWorld() $extclient.HelloSun() $extclient