我在执行此脚本时遇到问题导致我不理解的错误,脚本运行完美,总是。
如果有人知道这个错误可能是什么原因,那将非常有帮助。
这是剧本:
Param(
[Parameter(Mandatory=$true)]
$domain = "lon.lab"
)
$name = Read-Host "Enter your computer name"
$username = "$domain\administrator"
$password = Read-Host -Prompt "Enter Password for $username" -AsSecureString
$cred = New-Object System.Management.Automation.PSCredential ($username, $password)
Add-Computer -DomainName $domain -Credential $cred -NewName $name
这是我得到的错误:
Add-Computer : Computer 'WIN-5V8QHNCLO9U' failed to join domain 'lon.lab' from its current workgroup 'WORKGROUP' with following error message: Cannot complete this function. At C:\Users\Administrator\Desktop\NewPcToDomain.ps1:10 char:1 + Add-Computer -DomainName $domain -Credential $cred + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (WIN-5V8QHNCLO9U:String) [Add-Computer], InvalidOperationException + FullyQualifiedErrorId : FailToJoinDomainFromWorkgroup,Microsoft.PowerShell.Commands.AddComputerCommand
修改:我添加了-Verbose
参数,如下所示:
Add-Computer -DomainName $domain -Credential $cred -NewName $name -Verbose
我只是不知道这是如何或为何有效。