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
23
cleanW10.ps1
23
cleanW10.ps1
|
@ -1,11 +1,17 @@
|
||||||
|
param (
|
||||||
|
[cmdletbinding()]
|
||||||
|
[string]$dir="modules.d",
|
||||||
|
[string]$file
|
||||||
|
)
|
||||||
#requires -RunAsAdministrator
|
#requires -RunAsAdministrator
|
||||||
|
|
||||||
Import-Module NetSecurity #Useful to manipulate firewall rules
|
Import-Module NetSecurity #Useful to manipulate firewall rules
|
||||||
Set-StrictMode -Version 2
|
Set-StrictMode -Version 2
|
||||||
|
$PSDefaultParameterValues=@{$dir = "./modules.d"}
|
||||||
$HOST_FILE = "$env:windir\System32\drivers\etc\hosts"
|
$HOST_FILE = "$env:windir\System32\drivers\etc\hosts"
|
||||||
$HOST_IP = "0.0.0.0"
|
$HOST_IP = "0.0.0.0"
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
$ProgressPreference = "SilentlyContinue"
|
$ProgressPreference = "SilentlyContinue"
|
||||||
|
|
||||||
#Thanks to https://gist.github.com/markembling/173887
|
#Thanks to https://gist.github.com/markembling/173887
|
||||||
function BlockHost {
|
function BlockHost {
|
||||||
param(
|
param(
|
||||||
|
@ -455,18 +461,19 @@ catch {
|
||||||
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Write-Host "Folder to process : $dir"
|
||||||
Get-ChildItem -Path $PSScriptRoot"\modules.d" -Filter "*.conf" | foreach {
|
Get-ChildItem -Path $dir -Filter "*.conf" | foreach {
|
||||||
$module = ""
|
$module = ""
|
||||||
try {
|
try {
|
||||||
$module = Get-Content $_.FullName -Raw | ConvertFrom-Json
|
$filename = $_.FullName
|
||||||
|
$module = Get-Content $filename -Raw | ConvertFrom-Json
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Host -NoNewline -ForegroundColor Red "Error While Loading JSON : $_.FullName"
|
Write-Host -NoNewline -ForegroundColor Red "Error While Loading JSON : $filename `n`n"
|
||||||
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
#Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Write-Host -ForegroundColor White "`nProcess Module $($module.name)"
|
Write-Host -ForegroundColor White "`nProcess Module $($module.name) `n"
|
||||||
$module_dir = $_.Directory.FullName + "\" + $_.BaseName + "\"
|
$module_dir = $_.Directory.FullName + "\" + $_.BaseName + "\"
|
||||||
$module.actions | Foreach {
|
$module.actions | Foreach {
|
||||||
$action_file = ""
|
$action_file = ""
|
||||||
|
@ -499,4 +506,4 @@ try {
|
||||||
catch {
|
catch {
|
||||||
Write-Host -NoNewline -ForegroundColor Red "Error`n`t"
|
Write-Host -NoNewline -ForegroundColor Red "Error`n`t"
|
||||||
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue