Bonjour, je suis en train de créer un script d'automatisation d'installation d'un poste .
J'ai un souci, je dois renommer et intégrer le poste à un domaine .
Jusque là pas de soucis, powershell permet de faire ça facilement, MAIS (car il y a un gros MAIS), je veux renommer
le poste et l'intégrer sans redémarrer(enfin pas tout de suite) .
Le souci est que le renommage se passe bien l'intégration aussi,mais le poste est intégré avec l'ancien nom,
car il faut redémarrer le pc pour que le nouveau nom soit pris en compte avec Rename-Computer.
Je précise que je sais que c'est faisable car un script python le fait en utilisant SetComputerNameExW et NetJoinDomain
J'ai donc insérer les fonctions SetComputerNameExW de la lib kernel32.dll er NetJoinDomain de la lib netapi32.dll
.
j'ai fait comme ça :
#Building the definition
$Kernel32Definition = @'
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern bool SetComputerNameExW(int NameType, string lpBuffer);
'@
$Netapi32Definition = @'
[DllImport("netapi32.dll", CharSet = CharSet.Unicode)]
public static extern uint NetJoinDomain(
string lpServer,
string lpDomain,
string lpAccountOU,
string lpAccount,
string lpPassword,
int NameType);
'@
#Adding the definition to get the system runtime.
$Kernel32 = Add-Type -MemberDefinition $Kernel32Definition -Name 'SetComputerNameExW_Kernel32' -Namespace 'Win32' -PassThru
$NetApi32 = Add-Type -MemberDefinition $Netapi32Definition -Name 'NetJoinDomain_Netapi32' -Namespace 'Win32' -PassThru
$Kernel32::SetComputerNameExW(5 ,"TOTO")
$NetApi32::NetJoinDomain("Mon_Serveur","Mon_domaine",$Null,"mon_login","mon_mdp",1059)
SetComputerNameExW fonctionne bien, mais pas NetJoinDomain qui ne fait aucune erreur mais ne fait rien .
Dans la commande NetJoinDomain il y a un flag qui semble prévu à cet effet (joindre le domaine avec un nouveau
nom,ou j'ai mal compris son utilisation)
NETSETUP_JOIN_WITH_NEW_NAME 0x00000400
Join the target machine specified in lpServer parameter with a new name queried from the registry on the machine specified in the lpServer parameter.
This option is used if SetComputerNameEx has been called prior to rebooting the machine. The new computer name will not take effect until a reboot. With this option, the caller instructs the NetJoinDomain function to use the new name during the domain join
operation. A reboot is required after calling NetJoinDomain successfully at which time both the computer name change and domain membership change will have taken affect.
Je précise que je ne veux pas utiliser Rename-Computer+Add-Computer qui marchent, mais m'intégre la station
avec l'ancien nom .
Si quelqu'un a une solution, merci d'avance .