Add -file parameter + Better message when JSON error
Add -file parameter + Better message when JSON error
This commit is contained in:
parent
c209024de0
commit
e0c4d6361e
1 changed files with 15 additions and 8 deletions
21
cleanW10.ps1
21
cleanW10.ps1
|
@ -1,11 +1,17 @@
|
|||
param (
|
||||
[cmdletbinding()]
|
||||
[string]$dir="modules.d",
|
||||
[string]$file
|
||||
)
|
||||
#requires -RunAsAdministrator
|
||||
|
||||
Import-Module NetSecurity #Useful to manipulate firewall rules
|
||||
Set-StrictMode -Version 2
|
||||
$PSDefaultParameterValues=@{$dir = "./modules.d"}
|
||||
$HOST_FILE = "$env:windir\System32\drivers\etc\hosts"
|
||||
$HOST_IP = "0.0.0.0"
|
||||
$ErrorActionPreference = "Stop"
|
||||
$ProgressPreference = "SilentlyContinue"
|
||||
|
||||
#Thanks to https://gist.github.com/markembling/173887
|
||||
function BlockHost {
|
||||
param(
|
||||
|
@ -455,18 +461,19 @@ catch {
|
|||
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
||||
return
|
||||
}
|
||||
|
||||
Get-ChildItem -Path $PSScriptRoot"\modules.d" -Filter "*.conf" | foreach {
|
||||
Write-Host "Folder to process : $dir"
|
||||
Get-ChildItem -Path $dir -Filter "*.conf" | foreach {
|
||||
$module = ""
|
||||
try {
|
||||
$module = Get-Content $_.FullName -Raw | ConvertFrom-Json
|
||||
$filename = $_.FullName
|
||||
$module = Get-Content $filename -Raw | ConvertFrom-Json
|
||||
}
|
||||
catch {
|
||||
Write-Host -NoNewline -ForegroundColor Red "Error While Loading JSON : $_.FullName"
|
||||
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
||||
Write-Host -NoNewline -ForegroundColor Red "Error While Loading JSON : $filename `n`n"
|
||||
#Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
||||
return
|
||||
}
|
||||
Write-Host -ForegroundColor White "`nProcess Module $($module.name)"
|
||||
Write-Host -ForegroundColor White "`nProcess Module $($module.name) `n"
|
||||
$module_dir = $_.Directory.FullName + "\" + $_.BaseName + "\"
|
||||
$module.actions | Foreach {
|
||||
$action_file = ""
|
||||
|
|
Reference in a new issue