$outputFolder = "c:\audit"
$outputFile = "output.csv"
if (!(Test-Path $outputFolder)) {
New-Item $outputFolder -Type Directory
}
$outputPath = $outputFolder + "\" + $outputFile
Get-ChildItem -Path "C:\Temp\Lister et auditer\Web.config\web.config1\*.config" | ForEach-Object {
$filePath = $_.FullName
# Pour voir en live l'affectation
Write-Debug $filepath
$fileName = $_.Name
Copy-Item -LiteralPath $filePath -Destination ($filePath).Replace($fileName,("_"+$fileName))
(Get-Content $filePath) | ForEach-Object {
if ($_ -match 'Compilation debug.?=.?"true"') { $CompilationDebug = $true }
else { $CompilationDebug = $false}
if ($_ -match 'Trace enable.?=.?"true"') { $TraceEnabled = $true }
else { $traceEnabled = $false}
if ($_ -match 'customErrors mode.?=.?"On"') { $customErrorsMode = $On }
else { $customErrorsMode = $Off}
if ($_ -match 'directoryBrowse enabled.?=.?"true"') { $directoryBrowseEnabled = $true }
else { $directoryBrowseEnabled = $false}
#$_ -Replace 'Compilation debug.?=.?"true"', 'Compilation debug="false"'
#$_ -Replace 'Trace enable.?=.?"true"', 'Trace enable="false"'
#$_ -Replace 'customErrors mode.?=.?"On"', 'customErrors mode="Off"'
#$_ -Replace 'directoryBrowse enabled.?=.?"true"', 'directoryBrowse enabled="false"'
"$$outputFile;$CompilationDebug;$TraceEnabled;$customErrorsMode;$directoryBrowseEnabled" | Out-File -Path C:\Temp\test.csv $outputPath -Append
} |
Set-Content $filePath
Write-Host "Press any key to continue …"
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
Partager