首页 > 解决方案 > 试图重命名计算机。但是脚本调用深度溢出失败

问题描述

我有一个 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

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

标签: powershell

解决方案


推荐阅读