尝试重命名计算机。但是脚本无法调用深度溢出

时间:2019-05-07 05:14:37

标签: powershell

我具有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

我做错了什么?我似乎无法在脚本中找到任何递归调用来获取调用深度溢出错误。

0 个答案:

没有答案