From e0c4d6361ed442239b5346657aaf6113a7e329f8 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Fri, 23 Mar 2018 21:40:20 +0100 Subject: [PATCH] Add -file parameter + Better message when JSON error Add -file parameter + Better message when JSON error --- cleanW10.ps1 | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/cleanW10.ps1 b/cleanW10.ps1 index e09fbfb..ed7831b 100755 --- a/cleanW10.ps1 +++ b/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 = "" @@ -499,4 +506,4 @@ try { catch { Write-Host -NoNewline -ForegroundColor Red "Error`n`t" Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message -} \ No newline at end of file +}