Voici un script qui permet de mettre à jour des serveurs WINS sur les cartes réseaux actives d’un ou plusieurs serveurs/ordinateurs.
Il suffit de remplir au préalable un fichier “TXT” qui servira de fichier d’import et lancer le script.
Vous aurez une fenêtre vous demandant de sélectionner le fichier d’import.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
#========================================================================================= # # NAME: Winsserver_networkcard # # AUTHOR: Mehdi.JERBI # # USAGE: modify wins setting on network card. # # PREREQUISITE: You must have Excel, Power shell #========================================================================================== #Import TXT file Function Get-FileName($initialDirectory) { [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog $OpenFileDialog.initialDirectory = $initialDirectory $OpenFileDialog.filter = $null $OpenFileDialog.ShowDialog() | Out-Null $OpenFileDialog.filename if ($OpenFileDialog.filename -eq "") { Write-Host "file not found" exit } } $Inputfile = Get-FileName "C:\" $Records = Import-Csv -Path $Inputfile -Delimiter ";" $ErrorActionPreference = "Continue" #Creation of output file $ScriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition $CurrentDate = Get-Date -format yyyyMMdd_hhmmss $ResultFile = $ScriptPath+ "\" + $CurrentDate + "_WINSmodification_result.csv" #build of the result $a = New-Object -comobject Excel.Application $a.Visible = $True $b = $a.Workbooks.Add() $c = $b.Worksheets.Item(1) $col = 1 $ligne = 1 $c.Cells.Item(1,1) = "Serveur" $c.Cells.Item(1,1).Interior.colorindex = 15 $c.Cells.Item(1,2) = "Resultat" $c.Cells.Item(1,2).Interior.colorindex = 15 $c.Cells.Item(1,3) = "WINS Serveurs" $c.Cells.Item(1,3).Interior.colorindex = 15 $ligne++ #search NIC Prod of server. foreach ($server in $records) { $nic = $null $nic = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $server.name | where{$_.IPAddress -like $server.ipadress} $check_error = $NIC.SetWINSServer("192.168.1.1","192.168.1.2") # check errors if ($check_error.returnvalue -ne "0") { $col = 1 $c.Cells.Item($ligne,$col) = [string]$server.name $col++ $c.Cells.Item($ligne,$col) = "error" + $check_error.returnvalue $col++ $c.Cells.Item($ligne,$col) = $nic.WINSPrimaryServer + "/" + $nic.WINSSecondaryServer $col++ $ligne ++ } else { $nic = $null $nic = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $server.name | where{$_.IPAddress -like $server.ipadress} $col = 1 $c.Cells.Item($ligne,$col) = [string]$server.name $col++ $c.Cells.Item($ligne,$col) = "OK" $col++ $c.Cells.Item($ligne,$col) = $nic.WINSPrimaryServer + "/" + $nic.WINSSecondaryServer $col++ $ligne ++ } } #autosize colum $c.columns.item("A:C").EntireColumn.AutoFit() #save XLS files $b.SaveAs($ResultFile) |