I seriously apologize for the awful title of this post ... but I'm new to OOP and PowerShell, so I have absolutely no idea how to spell out what I ask. After learning that I can use PowerShell to connect to the API and the like, I worked on it non-stop. Now I am working on a script where I need to create a class. I have done this successfully, and I can create methods and use them. At the moment, all my objects and methods have only one level .... So if I call a method on an object, it always looks like this: $ foo.run ()
But I want to create something like $ foo.bar.run ()
I wrote a script that uses my TV API. So currently I have commands like this:
$tv.TurnOn()
$tv.TurnOff()
$tv.GetPowerStatus()
$tv.ListInputs()
$tv.GetCurrentInput()
$tv.SetInput($name)
But I would like to do this instead:
$tv.Power.On()
$tv.Power.Off()
$tv.Power.Status()
$tv.Input.List()
$tv.Input.Current()
$tv.Input.Set($name)
Is it possible?
, , , , , . #. , #, .
:
Class VizioTV {
[String]$IPAddress
[String]$AuthToken
[void]TurnOn() {
Set-Power -action "on" -IPAddress $this.IPAddress -auth $this.AuthToken
}
[void]TurnOff() {
Set-Power -action "off" -IPAddress $this.IPAddress -auth $this.AuthToken
}
[String]GetPowerStatus() {
Return Get-PowerStatus -IPAddress $this.IPAddress -auth $this.AuthToken
}
}