Comment puis-je garder l'ordinateur ajouté de l'échec de la moitié de l'heure sur une machine avec Dual Nics?

StackOverflow https://stackoverflow.com//questions/24024922

  •  21-12-2019
  •  | 
  •  

Question

J'essaie d'ajouter un ordinateur à un domaine à l'aide de la cmdlet Ajouter un ordinateur, mais la cmdlet échoue à la moitié du temps avec l'erreur suivante:

Le nom demandé est valide, mais aucune donnée du type demandé n'a été trouvée

Je suis presque positif, cela est dû au fait qu'il y a deux niques sur le PC, mais une seule d'entre elles est utilisée.Si quelqu'un a une idée de la façon de contourner cette limitation avec le chemin du moindre résistance, il serait grandement apprécié.

Veuillez garder à l'esprit que cela se passe dans un script pour un grand déploiement de PC, la désactivation manuelle de la carte réseau secondaire n'est donc pas vraiment une option que si elle est automatisée.

Voici le code que j'utilise:

# 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

merci!

Était-ce utile?

La solution

Étant donné qu'aucun des PC, le script serait en cours d'exécution aura plus de deux NICS, voici comment j'ai résolu le problème:

# 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
}

assez simple pour mon usage.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top