104 lines
3.2 KiB
PowerShell
104 lines
3.2 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
<Overview of script>
|
|
|
|
.NOTES
|
|
Version : 1.0
|
|
Author : Hubert CORNET
|
|
Creation Date : <Date>
|
|
Purpose/Change : <Initial script development>
|
|
|
|
.LINK
|
|
https://www.tips-of-mine.fr
|
|
|
|
.EXEMPLE
|
|
<Example goes here. Repeat this attribute for more than one example>
|
|
|
|
.DESCRIPTION
|
|
<Brief description of script>
|
|
|
|
.PARAMETER <Parameter_Name>
|
|
<Brief description of parameter input required. Repeat this attribute if required>
|
|
|
|
.INPUTS
|
|
<Inputs if any, otherwise state None>
|
|
|
|
.OUTPUTS
|
|
<Outputs if any, otherwise state None - example: Log file stored in C:\Windows\Temp\<name>.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 = "<script_name>.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" |