本文介绍了PowerShell-用与函数相同的名称覆盖该cmdlet的名称时,如何在该函数中调用cmdlet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一个名为update-name的cmdlet,我无权对其进行更改.
So I have a cmdlet named update-name that I have no access to change.
我创建了一个名为update-name(与cmdlet相同的名称)的函数.如何从具有相同名称的函数调用cmdlet?
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
}
不幸的是,如果它是CmdLet,则无法使用.
Unfortunately that doesn't work if it is a CmdLet.
推荐答案
您可以使用cmdlet的模块名称来消除名称的歧义:
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
这篇关于PowerShell-用与函数相同的名称覆盖该cmdlet的名称时,如何在该函数中调用cmdlet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!