Set Default File Association - Please Help


Im stuck for some reason that I dont know this is not working any advice on how to change default file associations would be highly appreciated.

this is what I have so far… thank you

[string]$extension = 'txt'
[string]$executable = "C:\Program Files (x86)\Notepad++\notepad++.exe"

if (-not (Test-Path $executable))
	$errorMessage = "`'$executable`' does not exist, not able to create association"

	throw $errorMessage
$extension = $extension.trim()
if (-not ($extension.StartsWith(".")))
	$extension = ".$extension"
$fileType = Split-Path $executable -leaf
$fileType = $fileType.Replace(" ", "_")
$elevated = @"
    cmd /c "assoc $extension=$fileType"
    cmd /c 'ftype $fileType="$executable" "%1" "%*"'
    New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
    Set-ItemProperty -Path "HKCR:\$fileType" -Name "(Default)" -Value "$fileType file" 
-ErrorAction Stop
iex $elevated

In your second Cmd, the string is delimited with single quotes, so won’t do variable replacement. Only the outermost quotes count for this - the fact that you’ve used double quotes inside doesn’t matter.

Thx Don!