6

Please excuse me if you find this a very lame questions, but since I am learning Powershell I need to ask.

This is a sort of next part of the question posted and answer received here.

I have a custom cmdlet named Get-DirectoryListing and I added an alias 'gdl' (using New-Alias command in .psm1 file). So user can use either Get-DirectoryListing or gdl to fire the same command. Now I want to detect in my code (.NET, C#) which text was used to execute the command. Lets say if user used alias 'gdl' to execute the command, I want to show message like

'This alias is deprecated and shouldn't be used.'

But I do not want to show this message if user uses Get-DirectoryListing to execute the command.

What is the best way to achieve this?

Community
  • 1
  • 1
digitguy
  • 1,014
  • 2
  • 12
  • 29

1 Answers1

4

Inspect the

this.MyInvocation.InvocationName

property on your PSCmdlet instance.

Keith Hill
  • 194,368
  • 42
  • 353
  • 369