Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 cmdlet from the function with the same name?

I've tried a few things and none of them seem to work.

function update-name {
param([string] something)
  #call cmdlet update-name here
}

There is a way to do it when it is just functions:

$unBackup = 'DefaultUpdateName'
if(!(Test-Path Function:\$unBackup)) {
    Rename-Item Function:\Update-Name $unBackup
}

function update-name {
  & $unName
}

Unfortunately that doesn't work if it is a CmdLet.

like image 475
ferventcoder Avatar asked Apr 05 '11 18:04

ferventcoder


People also ask

Which command lists cmdlets related to aliases?

The cmdlet Get-Alias outputs a list of all the aliases available in the PowerShell session. Aliases are short names or alternate commands for longer PowerShell cmdlets.

Is not recognized as the name of a cmdlet function?

If that module is missing, corrupt, or got moved, it throws up the error, “the term is not recognized as the name of a cmdlet.” You can use “get-module” in PowerShell to see if the module is present and correct. It will show you what modules are loaded, and you can add or repair them depending on your needs.

How are PowerShell cmdlets identified?

PowerShell uses a verb-and-noun name pair to name cmdlets. For example, the Get-Command cmdlet included in PowerShell is used to get all the cmdlets that are registered in the command shell.

What term is used to describe an alternate name for a cmdlet in PowerShell?

Long descriptionAn alias is an alternate name or nickname for a cmdlet or for a command element, such as a function, script, file, or executable file. You can use the alias instead of the command name in any PowerShell commands.


1 Answers

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
like image 197
Keith Hill Avatar answered Oct 19 '22 08:10

Keith Hill