0

We can create alias name for function.

Is there a way to create alias name for Scriptmethod (created by Add-member)?

The scenario is as below.

$TestSuite | Add-Member -MemberType ScriptMethod TestId_6099 {

}

We are having test suite where a method name TestId_6099 is there. This method is doing for example: Check Disk limit exceed event.

So the proper name could be

$TestSuite | Add-Member -MemberType ScriptMethod CheckDiskLimitExceedAlert {

}

Then there should be alias name for the scriptmethod should be as TestId_6099.

There is an aliasproperty membertype but it is not working for scriptmethod. How to create alias name for ScriptMethod?

1 Answer 1

1

This is a bit hacky, but you can have a self-referencing ScriptMethod:

$TestProject = New-Object PsObject

$TestProject | Add-Member -MemberType ScriptMethod TestId_6099 {
    Write-Host "Hell Is For Heroes"
}

$TestProject | Add-Member -MemberType ScriptMethod GreatestBandEver {
    $this.TestId_6099()
}

$TestProject.GreatestBandEver()

Result: Hell Is For Heroes

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.