PowerShell - How do I call a cmdlet in a function when overriding that cmdlet's name with the same name as the function?

后端 未结 3 1771
无人及你
无人及你 2020-12-29 13:30

So I have a cmdlet named update-name that I have no access to change.

I have created a function named update-name (the same name as the cmdlet). How do I call the c

相关标签:
3条回答
  • 2020-12-29 14:22

    You the cmdlet's module name to disambiguate the names:

    PS> Get-Command Start-Process | Format-Table ModuleName
    
    ModuleName
    ----------
    Microsoft.PowerShell.Management
    
    PS> Microsoft.PowerShell.Management\Start-Process Notepad
    
    0 讨论(0)
  • 2020-12-29 14:24

    This will do the trick as well - thanks Keith Dahlby! http://twitter.com/dahlbyk/status/55341994817503232

    $unName=Get-Command 'Update-Name' -CommandType Cmdlet;
    
    function update-name {
      & $unName
    }
    
    0 讨论(0)
  • 2020-12-29 14:26

    Can you use a proxy function?

    0 讨论(0)
提交回复
热议问题