Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find which Cmdlet Alias was used by user?

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?

like image 438
digitguy Avatar asked Nov 28 '12 05:11

digitguy


1 Answers

Inspect the

this.MyInvocation.InvocationName

property on your PSCmdlet instance.

like image 86
Keith Hill Avatar answered Oct 13 '22 11:10

Keith Hill