У вас уже есть решение вашей проблемы, но, как я уже говорил, прокси-функция может подойти в этом конкретном сценарии. Вот рабочий пример (по крайней мере, для PSVersion 5.1).
Добавление следующего в ваш профиль $ должно работать, и вы сможете запустить rm -rf "path"
для рекурсивного и принудительного удаления каталога. Имейте в виду, что это не было тщательно протестировано, но оно учитывает, указали ли вы -rf или нет в командной строке. Он также поддерживает общие параметры, такие как -Confirm:$true
.
if(Test-Path Alias:rm) { Remove-Item Alias:rm }
function rm
{
[CmdletBinding(DefaultParameterSetName='Path', SupportsShouldProcess=$true, ConfirmImpact='Medium', SupportsTransactions=$true, HelpUri='https://go.microsoft.com/fwlink/?LinkID=113373')]
param(
[Parameter(ParameterSetName='Path', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[string[]]
${Path},
[Parameter(ParameterSetName='LiteralPath', Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[Alias('PSPath')]
[string[]]
${LiteralPath},
[string]
${Filter},
[string[]]
${Include},
[string[]]
${Exclude},
[switch]
${Recurse},
[switch]
${Force},
[switch]
${rf},
[Parameter(ValueFromPipelineByPropertyName=$true)]
[pscredential]
[System.Management.Automation.CredentialAttribute()]
${Credential})
begin
{
try {
$outBuffer = $null
if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
{
$PSBoundParameters['OutBuffer'] = 1
}
if($rf)
{
$PSBoundParameters.Remove('rf') | Out-Null
$PSBoundParameters.Add('Recurse', $true) | Out-Null
$PSBoundParameters.Add('Force', $true) | Out-Null
}
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Management\Remove-Item', [System.Management.Automation.CommandTypes]::Cmdlet)
$scriptCmd = {& $wrappedCmd @PSBoundParameters }
$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
$steppablePipeline.Begin($PSCmdlet)
} catch {
throw
}
}
process
{
try {
$steppablePipeline.Process($_)
} catch {
throw
}
}
end
{
try {
$steppablePipeline.End()
} catch {
throw
}
}
<#
.ForwardHelpTargetName Microsoft.PowerShell.Management\Remove-Item
.ForwardHelpCategory Cmdlet
#>
}