function Set-PowAsDefault { [CmdletBinding()] Param ( [Parameter(mandatory=$false,ValueFromPipeline=$false)] [Alias("Active")] [switch] [bool]$On ) begin { if ($On.IsPresent) { Write-Host "Call Powershell for .PS1 files." } else { Write-Host "Try to go back." } } Process { # Text Menu [string]$TexteMenu = "Go inside PowerShell" # Text of the program to create [string] $TexteCommande = "%systemroot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command ""&'%1'""" # Key to create [String] $clefAModifier = "HKLM:\SOFTWARE\Classes\Microsoft.PowerShellScript.1\Shell\Open\Command" try { $oldCmdKey = $null $oldCmdKey = Get-Item $clefAModifier -ErrorAction SilentlyContinue $oldCmdValue = $oldCmdKey.getvalue("") if ($oldCmdValue -ne $null) { if ($On.IsPresent) { $slxOldValue = $null $slxOldValue = Get-ItemProperty $clefAModifier -Name "slxOldValue" -ErrorAction SilentlyContinue if ($slxOldValue -eq $null) { New-ItemProperty $clefAModifier -Name "slxOldValue" -Value $oldCmdValue -PropertyType "String" | Out-Null New-ItemProperty $clefAModifier -Name "(default)" -Value $TexteCommande -PropertyType "ExpandString" | Out-Null Write-Host "Done !" } else { Write-Host "Already done !" } } else { $slxOldValue = $null $slxOldValue = Get-ItemProperty $clefAModifier -Name "slxOldValue" -ErrorAction SilentlyContinue if ($slxOldValue -ne $null) { New-ItemProperty $clefAModifier -Name "(default)" -Value $slxOldValue."slxOldValue" -PropertyType "String" | Out-Null Remove-ItemProperty $clefAModifier -Name "slxOldValue" Write-Host "Done !" } else { Write-Host "No former value !" } } } } catch { $_.exception.message } } end {} } Set-PowAsDefault -On