I need $this to work inside a static class! How to do it? Any workaround? I analyzed the return of Get-PSCallStack in the context of the class and did not find anything useful.
I need this to (a) log and (b) call other static methods of the same class without mentioning its name again and again.
Sample code (PowerShell v5):
class foo { static [void]DoSomething() { [foo]::DoAnything() #works #$this.DoAnything #not working $static_this = [foo] $static_this::DoAnything() #works } static [void]DoAnything() { echo "Done" } } [foo]::DoSomething()
source share