Files

15 lines
473 B
PowerShell

#powershell -noprofile -command "Set-ExecutionPolicy bypass LocalMachine"
# On met l'adresse du client en variable
$IP = ((Test-Connection $env:COMPUTERNAME -Count 1).IPV4Address).ipaddresstostring
# Nslookup sur $IP
$nomfqdn = (nslookup $IP | Select-String "$IP" -Context 1,0).Context.precontext.substring(9)
# Retrait du groupe et du domain
$nonpc = $nomfqdn.Substring(0,$nomfqdn.IndexOf("."))
# Renommage du PC
Rename-Computer -NewName "$nonpc"
#restart-computer