Compare commits

...

8 commits

View file

@ -225,7 +225,7 @@ function AddRegKey {
return return
} }
if ( -not $params.ContainsKey('value') ) { if ( -not $params.ContainsKey('value') ) {
$params.value = "" $params.value = $null
} }
if ( -not $params.ContainsKey('type') -or $params.type -eq "" ){ $params.type="DWord" } if ( -not $params.ContainsKey('type') -or $params.type -eq "" ){ $params.type="DWord" }
@ -251,13 +251,12 @@ function AddRegKey {
} }
#Let's begin... #Let's begin...
Write-Host -NoNewline "`t$($params.path.substring(0,30))...$($params.key) reg key to $($params.value) : " Write-Host -NoNewline "`t$($params.path.substring(0,30))...$($params.key) reg key to '$($params.value)' : "
if ( -not (Test-Path $params.path) ){ if ( -not (Test-Path $params.path) ){
Write-Host -NoNewline -ForegroundColor DarkGreen "creating path " Write-Host -NoNewline -ForegroundColor DarkGreen "creating path "
try { try {
New-Item -Path $params.path -Force | Out-Null New-Item -Path $params.path -Force | Out-Null
} }
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
@ -267,12 +266,13 @@ function AddRegKey {
# Test if the key already exist # Test if the key already exist
try { try {
$current_value = Get-ItemPropertyValue -Path $params.path -Name $params.key $current_value = (Get-ItemPropertyValue -Path $params.path -Name $params.key)
if ( $current_value -eq $params.value ) { #current_value and params.value both empty need a special condition
if ( ( [string]::IsNullOrWhitespace($current_value) -and [string]::IsNullOrWhitespace($params.value) ) -or ($current_value -eq $params.value) ) {
Write-Host -ForegroundColor Yellow "Already done" Write-Host -ForegroundColor Yellow "Already done"
return return
} }
else { Write-Host -NoNewline -ForegroundColor DarkGreen "old value $current_value " } else { Write-Host -NoNewline -ForegroundColor DarkGreen " old value $current_value - " }
} }
catch { catch {
Write-Host -NoNewline -ForegroundColor DarkGreen "new key " Write-Host -NoNewline -ForegroundColor DarkGreen "new key "
@ -319,15 +319,14 @@ function DelRegKey {
return return
} }
try { try {
Get-ItemProperty -Path $params.path -Name $params.key Get-ItemProperty -Path $params.path -Name $params.key -ErrorAction Stop | Out-Null
} }
catch { catch {
Write-Host -ForegroundColor Yellow "key already deleted" Write-Host -ForegroundColor Yellow "key not exist (already deleted?)"
return return
} }
try { try {
Remove-ItemProperty -Path $params.path -Name $params.key
#Remove-ItemProperty -Path $params.path -Name $params.key
Write-host -ForegroundColor Green "done" Write-host -ForegroundColor Green "done"
} }
catch [System.Security.SecurityException]{ catch [System.Security.SecurityException]{
@ -391,6 +390,9 @@ function UninstallModernApp {
)] )]
[object]$params [object]$params
) )
if ( $params.ContainsKey('removeProvisioned') -and $params.removeProvisioned -eq $true ) {
UninstallModernProvisionedApp $params
}
if ( $params.ContainsKey('file') ) { if ( $params.ContainsKey('file') ) {
$pkgs = $(Get-AppxPackage -AllUsers).name $pkgs = $(Get-AppxPackage -AllUsers).name
$uninstall_list = Get-Content $params.file | Where { $_ -notmatch "^#.*$|^$" } $uninstall_list = Get-Content $params.file | Where { $_ -notmatch "^#.*$|^$" }
@ -414,10 +416,6 @@ function UninstallModernApp {
} }
else { else {
Write-Host -ForegroundColor Red "`tError : No name or file for action $($MyInvocation.MyCommand.Name)" Write-Host -ForegroundColor Red "`tError : No name or file for action $($MyInvocation.MyCommand.Name)"
return
}
if ( $params.ContainsKey('removeProvisioned') -and $params.removeProvisioned -eq $true ) {
UninstallModernProvisionedApp $params
} }
} }
@ -591,18 +589,19 @@ function ExecCommand {
) )
$path = $params.path.Replace("##mod_path##", $script:current_module_path) $path = $params.path.Replace("##mod_path##", $script:current_module_path)
$args = $params.arguments.Replace("##mod_path##", $script:current_module_path) $args = $params.arguments.Replace("##mod_path##", $script:current_module_path)
Write-Host -NoNewline "`tExecute : $path : " Write-Host "`n`tExecute $path : "
$path = Invoke-Expression """$($path)""" $path = Invoke-Expression """$($path)"""
if ( -not (Test-Path $path) -and -not $path -eq "powershell" ) { if ( -not ((Test-Path $path) -or $path -eq "powershell") ) {
Write-Host -ForegroundColor Yellow "File not found" Write-Host -ForegroundColor Yellow "`t`tFile not found"
return return
} }
try { try {
Start-Process -NoNewWindow -wait -filepath $path -ArgumentList $args Start-Process -NoNewWindow -wait -filepath $path -ArgumentList $args -ErrorAction Stop
Write-Host -ForegroundColor Green "`t`tExecution done"
} }
catch { catch {
Write-Host -NoNewLine -ForegroundColor Red "Error`n`t" Write-Host -NoNewLine -ForegroundColor Red "`tError`n`t`t"
write-Host -ForegroundColor DarkRed $Error[0].Exception.Message Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
} }
} }
@ -673,7 +672,7 @@ try {
catch { catch {
Write-Host -NoNewline -ForegroundColor Red "Error while mounting Registery`n`t" Write-Host -NoNewline -ForegroundColor Red "Error while mounting Registery`n`t"
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
#return return
} }
#We need access to users registry hive for applying mofidication to existing users #We need access to users registry hive for applying mofidication to existing users
@ -701,14 +700,15 @@ $script:users | foreach {
Write-Host -ForegroundColor Yellow "Already mounted" Write-Host -ForegroundColor Yellow "Already mounted"
} }
} }
Write-Host "Folder to process : $module"
if ( $debug ) { if ( $debug ) {
$DebugPreference = "Continue" $DebugPreference = "Continue"
} }
if ( $module -and $( Test-Path $module ) ) { if ( $module -and $( Test-Path $module ) ) {
Write-Host "File to process : $module"
$module | ProcessModuleFile $module | ProcessModuleFile
} }
else { else {
Write-Host "Folder to process : $dir"
Get-ChildItem -Path $dir -Filter "*.conf" | foreach { Get-ChildItem -Path $dir -Filter "*.conf" | foreach {
$_.FullName | ProcessModuleFile $_.FullName | ProcessModuleFile
} }
@ -724,7 +724,7 @@ 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
} }
0
[gc]::collect() [gc]::collect()
Write-Host "`nUnload Users hives : " Write-Host "`nUnload Users hives : "
#Unmount Registery #Unmount Registery