Create_baseline_script.ps1

 avatar
user_7881442
powershell
a month ago
1.2 kB
3
Indexable
Never
$BaselinePath = "C:\Baseline" = Join-Path -Path $BaselinePath -ChildPath "ConfigurationBaseline.txt" # Create the baseline directory if it doesn't exist if (-not (Test-Path -Path $BaselinePath)) { New-Item -ItemType Directory -Path $BaselinePath | Out-Null } # Define the file paths to include in the baseline $FileList = @( "C:\Windows\ntoskrnl.exe", "C:\Windows\explorer.exe", "C:\Windows\win.ini", "C:\Windows\System32\kernel32.dll", "C:\Windows\System32\services.exe", "C:\Windows\System32\svchost.exe" ) # Create a hashtable to store the file information $BaselineData = @{} # Iterate through the file paths and retrieve their information foreach ($FilePath in $FileList) { if (Test-Path -Path $FilePath -PathType Leaf) { $FileInfo = Get-Item -Path $FilePath $FileProperties = @{ "Name" = $FileInfo.Name "Path" = $FileInfo.FullName "Size" = $FileInfo.Length "LastWriteTime" = $FileInfo.LastWriteTime } $BaselineData[$FilePath] = $FileProperties } } # Export the baseline data to a file $BaselineData | ConvertTo-Json | Out-File -FilePath $BaselineFilePath Write-Host "Configuration baseline file created successfully. Baseline file saved at: $BaselineFilePath"
Leave a Comment