<# .SYNOPSIS .NOTES Version : 1.0 Author : Hubert CORNET Creation Date : Purpose/Change : .LINK https://www.tips-of-mine.fr .EXEMPLE .DESCRIPTION .PARAMETER .INPUTS .OUTPUTS .log> #> #---------------------------------------------------------[Initialisations]-------------------------------------------------------- param ( [alias("i")] [string]$inputfile = $(read-host -Prompt "Enter the full path to the list of the CSV input file") ) # Définir l'action d'erreur pour continuer silencieusement $ErrorActionPreference = "SilentlyContinue" # Bibliothèques de fonctions requises #----------------------------------------------------------[Declarations]---------------------------------------------------------- # Version Script $sScriptVersion = "1.0" #Log File Info $sLogPath = "C:\Tmp" $sLogName = ".log" $sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName #-----------------------------------------------------------[Functions]------------------------------------------------------------ #------------------------------------------------------------[Script]-------------------------------------------------------------- cls #Initialized the output file $TimeStamp1 = $(((get-date).ToUniversalTime()).ToString("yyyyMMddTHHmmssZ")) $output = "C:\temp\ExportedDNSSetting$TimeStamp1.csv" Write-Host "--->Generating the new output file now...... $output " New-Item -Path $output -ItemType File > $null Add-Content -Path $output -Value '"Hostname","Adapter Index","IP Address","DNSServerSetting"' #Generate the DNS settings output Import-Csv $inputfile | foreach { $AdapaterSettings = Get-wmiobject -ClassName Win32_NetworkAdapterConfiguration -ComputerName $_.hostname -ErrorAction SilentlyContinue if($AdapaterSettings -eq $null) { Write-Host "--->Collect the DNS Configuration Failed for server -" $_.hostname -ForegroundColor Red $NewLine = "{0},{1},{2},{3}" ` -f $_.hostname,` $null,` $null,` "This server cannot be connected!!!" $NewLine | Add-Content -Path $output }else { Write-Host "--->Collect the DNS Configuration successfully for server -" $_.hostname -ForegroundColor Green Foreach ($ThisAdapaterSetting in $AdapaterSettings) { $NewLine = "{0},{1},{2},{3}" ` -f $_.hostname,` $ThisAdapaterSetting.Index,` [string]$ThisAdapaterSetting.IPAddress,` [string]$ThisAdapaterSetting.DNSServerSearchOrder $NewLine | Add-Content -Path $output } } } Write-Host "--->Data Collection is completed, the result is at $output"