Как я могу продолжать добавить добавку от сбой половины времени на машине с двойными ними?
-
21-12-2019 - |
Вопрос
Я пытаюсь добавить компьютер в домен, используя командлет Add-Computer, но командлет не удается полтора времени по следующей ошибке:
Запрошенное имя действительно, но данные запрошенного типа не были найдены
Я почти уверен, что это связано с тем, что на компьютере есть два никса, но только один из них используется.Если у кого-то есть идеи, как обойти это ограничение на пути наименьшего сопротивления, было бы значительно оценено.
Пожалуйста, имейте в виду, что это происходит в скрипте для большого развертывания ПК, поэтому вручную отключение вторичного NIC не является обязательным вариантом, если оно не автоматизировано.
Вот код, который я использую:
# Convert our plaintext password to a secure string and create the domain join credential
$securePassword = ConvertTo-SecureString $txtPassword -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential( `
($txtDomainToJoin + "\" + $txtPrivilegedUser), $securePassword)
# Now we'll begin attempting to join
try
{
# Try to see if the PC is already on the domain
try
{
$computer = Get-AdComputer -Credential $credential -identity $txtNewHostname
}
catch
{
# ErrorAction isn't configured for Get-ADComputer, therefore, we need to silently fail.
}
# If the PC is in fact on the domain, notify the user and error out
if(($computer | Select DistinguishedName) -ne $null)
{
[System.Windows.MessageBox]::Show( `
"Computer already exists in the domain. Please remove the computer from AD before continuing or domain join will fail.", `
"Warning", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning) | Out-Null
return $false
}
# Finally, let's try to join the domain
Add-Computer -Credential $credential -DomainName $txtIntendedDomain `
-OUPath $cboOU -Force -ErrorAction Stop
}
catch
{
# Notify the user if there is an issue
[System.Windows.MessageBox]::Show("Error joining domain. $($_.Exception.Message)", "Error", `
[System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error) | Out-Null
return $false
}
[System.Windows.MessageBox]::Show("Domain joined successfully. Press OK to reboot.", "Update success", `
[System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information) | Out-Null
return $true
.
Спасибо!
Решение
Поскольку ни один из ПК. Сценарий не будет работать, укажутся более двух NIC, вот как я решил проблему:
# Add-Computer will fail 50% of the time if there are more than 2 connected adapters enabled
$netAdapters = (Get-WmiObject Win32_NetworkAdapter | Where-Object {$_.NetConnectionStatus -eq 2})
# So disable one NIC
if($netAdapters.Count -gt 1)
{
($netAdapters | Select-Object -Last 1).Disable() | Out-Null
}
.
достаточно просто для моего использования.