我具有Powershell功能来重命名计算机。以下是脚本:
#region Download-GitRepositories
<#
.SYNOPSIS
This function will rename the computer to hardware serial number.
.EXAMPLE
Rename-Machine
#>
function Rename-Machine
{
$env:SerialNumber = "0001"
$newname = $env:SerialNumber
$oldname = $env:COMPUTERNAME
#Renamer the Computer.
$localcredential = Get-Credential
Rename-Computer –ComputerName $oldname –NewName $newname -LocalCredential $localcredential
}
当我通过运行Rename-Machine命令调用该函数时,它显示错误消息:
The script failed due to call depth overflow.
+ CategoryInfo : InvalidOperation: (0:Int32) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CallDepthOverflow
我做错了什么?我似乎无法在脚本中找到任何递归调用来获取调用深度溢出错误。