How to find which Cmdlet Alias was used by user?

家住魔仙堡 提交于 2019-12-12 11:11:08

问题


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?


回答1:


Inspect the

this.MyInvocation.InvocationName

property on your PSCmdlet instance.



来源:https://stackoverflow.com/questions/13598169/how-to-find-which-cmdlet-alias-was-used-by-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!