Como posso continuar a Adicionar-Computador falhar metade do tempo em um computador com duas Placas de rede?
-
21-12-2019 - |
Pergunta
Estou tentando adicionar um computador a um domínio usando o Add-Computador cmdlet, mas o cmdlet falhará metade do tempo e com o seguinte erro:
O nome solicitado é válido, mas nenhum dado do tipo pedido foi encontrado
Estou quase positivo, este é devido ao fato de que existem duas Placas de rede no PC, mas apenas um deles está em uso.Se alguém tiver alguma idéia de como contornar essa limitação com o caminho de menor resistência seria muito apreciada.
Por favor, tenha em mente que este é ir em um script para uma grande implementação de PCs, assim como desativar manualmente o adaptador secundário não é realmente uma opção, a menos que ele é automatizado.
Aqui está o código que estou usando:
# 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
Obrigado!
Solução
Uma vez que nenhum dos PCs o script executado no vão ter mais do que duas Placas de rede, veja como eu resolvi o problema:
# 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
}
Simples o suficiente para o meu uso.