La Référence Absolue sur les Technologies Microsoft




[Windows PowerShell] IPCONFIG à la sauce PowerShell...

Accueil > Script > reseau > [Windows PowerShell] IPCONFIG à la sauce PowerShell...

[Windows PowerShell] IPCONFIG à la sauce PowerShell...

Par Pierre-maxime JEANNEY, LABORATOIRE SUPINFO DES TECHNOLOGIES MICROSOFT
Publiée le 06/05/2007 vers 21h.

Voici un script PowerShell (IPconfig.ps1), semblable à la commande ipconfig sur WSH, très pratique.

$RegeditTCPIP = "HKLM:\System\CurrentControlSet\Services\TCPIP\Parameters"
$HostName = $(get-itemproperty $RegeditTCPIP).HostName
$DomainName = $(get-itemproperty $RegeditTCPIP).Domain
$Routing = $(get-itemproperty $RegeditTCPIP).IPEnableRouter
$DomainNameD = $(get-itemproperty $RegeditTCPIP).UseDomainNameDevolution

$RegeditNetBT = "HKLM:\System\CurrentControlSet\Services\NetBT\parameters"
$Nodetype = $(get-itemproperty $RegeditNetBT).DHCPNodeType
$LMhostsEnable = $(get-itemproperty $RegeditNetBT).EnableLMHosts

$NodeTypeSTR = "Inconnu"

Switch ($NodeType) {
 4 {$NodeTypeSTR = "Mixte"}
 8 {$NodeTypeSTR = "Hybride"}
 Else {$NodeTypeSTR = "Inconnu"}
}

$IPRouting = "Inconnu"

if ($routing -eq 0) {$IPRouting="Non"}
if ($routing -eq 1) {$IPRouting="Oui"}

$NetworkAdapterConfigurationWhere = Get-WMIObject Win32_NetworkAdapterConfiguration | WHERE {$_.IPEnabled}

# DNS - WINS

ForEach ($nic in $NetworkAdapterConfigurationWhere) {
 $DnsWins = $nic.DNSEnabledForWINSResolution
}

If  ($DnsWins) {
 $winsproxy = "Oui"
}
Else {
 $WinsProxy = "Non"
}

# Configuration globale

""
"Windows - Configuration IP"
""
"        Host Name . . . . . . . . . . . . : $HostName"
"        Primary DNS Suffix  . . . . . . . : $DomainName"
"        Type de noeud . . . . . . . . . . : $NodeTypeStr"
"        IP Routing Enabled. . . . . . . . : $IPRouting"
"        WINS Proxy Enabled. . . . . . . . : $WinsProxy"
"        Use DNS Domain Name Devloution. . : $([boolean]$DomainNameD)"
"        LMHosts Enabled . . . . . . . . . : $([boolean]$LMhostsEnable)"
"        DNS Suffix Search List. . . . . . : $DomainName"
""

$OSVersion = [float]$(Get-WMIObject Win32_OperatingSystem).version.substring(0,3)

# Paramètres par Adaptateur Réseau

$NetworkAdapterConfiguration = Get-WMIObject Win32_NetworkAdapterConfiguration
$NetworkAdapter = Get-WMIObject Win32_NetworkAdapter

For ($i=0 ; $i -lt $NetworkAdapter.length ; $i++) {
 $Nic = $NetworkAdapter[$i]
 $Configuration = $NetworkAdapterConfiguration[$i]
 
 # Affiche les informations pour les cartes branchées
   If ($Configuration.IPEnabled) {
  $Index = $Nic.Index
  $AdapterType = $Nic.AdapterType
  If ($OsVersion -gt 5.0) {
   $Connecteur = $Nic.NetConnectionID
  }
  Else {
   $Connecteur = $Nic.Index
  }

  "$($Nic.AdapterType) - Adaptateur : $Connecteur"
  ""
  " Connection-specific DNS Suffix. . : $($Configuration.DNSDomain)"
  " Description . . . . . . . . . . . : $($Nic.Description)"
  " Physical Address. . . . . . . . . : $($Nic.MACAddress)"
  " DHCP Enabled. . . . . . . . . . . : $($Configuration.DHCPEnabled)"
  " Autoconfiguration Enabled . . . . : $($Nic.AutoSense)"
  " IP Address. . . . . . . . . . . . : $($Configuration.IPAddress)"
  " Subnet Mask . . . . . . . . . . . : $($Configuration.IPSubnet)"
  " Default Gateway . . . . . . . . . : $($Configuration.DefaultIPGateway)"
  " DHCP Server . . . . . . . . . . . : $($Configuration.DHCPServer)"
  " DNS Servers . . . . . . . . . . . : $($Configuration.DNSServerSearchOrder)"
  " Primary WINS Server . . . . . . . : $($Configuration.WINSPrimaryServer)"
  " Secondary WINS Server . . . . . . : $($Configuration.WINSSecondaryServer)"
  " Lease Obtained. . . . . . . . . . : $($Configuration.DHCPLeaseObtained)"
  " Lease Expires . . . . . . . . . . : $($Configuration.DHCPLeaseExpires)"
  ""
 }
}



Proposer un script

Notre avis :

Votre avis :

Réactions :
0

Votants :
15

Visites :
10972

1
2
3
4
5




Retrouvez ci-dessous les autres sections du Laboratoire Microsoft