Better output for AddRegKey()
This commit is contained in:
parent
5e9148b111
commit
00e4a21767
1 changed files with 22 additions and 22 deletions
44
cleanW10.ps1
44
cleanW10.ps1
|
@ -220,10 +220,10 @@ function AddRegKey {
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[object]$params
|
[object]$params
|
||||||
)
|
)
|
||||||
if ( -not $params.ContainsKey('path') -or -not $params.ContainsKey('key') ) {
|
if ( -not $params.ContainsKey('path') -or -not $params.ContainsKey('key') ) {
|
||||||
Write-Host -ForegroundColor Red -NoNewline "Error in AddRegKey : no path, key or value`n"
|
Write-Host -ForegroundColor Red -NoNewline "Error in AddRegKey : no path, key or value`n"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ( -not $params.ContainsKey('value') ) {
|
if ( -not $params.ContainsKey('value') ) {
|
||||||
$params.value = ""
|
$params.value = ""
|
||||||
}
|
}
|
||||||
|
@ -251,28 +251,28 @@ 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 {
|
|
||||||
Write-Host -NoNewLine -ForegroundColor Red "Error`n`t"
|
|
||||||
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host -NoNewLine -ForegroundColor Red "Error`n`t"
|
||||||
|
Write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# 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 ) {
|
if ( -not $current_value ) { $current_value = "" }
|
||||||
Write-Host -ForegroundColor Yellow "Already done"
|
if ( $current_value -eq $params.value ) {
|
||||||
return
|
Write-Host -ForegroundColor Yellow "Already done"
|
||||||
}
|
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 "
|
||||||
|
@ -281,7 +281,7 @@ function AddRegKey {
|
||||||
# Put the key
|
# Put the key
|
||||||
try {
|
try {
|
||||||
Set-ItemProperty -Path $params.path -Name $params.key -Value $params.value -Type $params.type -Force
|
Set-ItemProperty -Path $params.path -Name $params.key -Value $params.value -Type $params.type -Force
|
||||||
Write-Host -ForegroundColor Green "done"
|
Write-Host -ForegroundColor Green "done"
|
||||||
}
|
}
|
||||||
catch [System.Security.SecurityException]{
|
catch [System.Security.SecurityException]{
|
||||||
Write-Host -ForegroundColor Red "Error (access denied)"
|
Write-Host -ForegroundColor Red "Error (access denied)"
|
||||||
|
|
Reference in a new issue