Sunday, February 10, 2019

Windows File Association From Powershell..


This power shell script will solve the file association issue in windows environment. If you want to open .log file from Notepad ++ or you want to open all the PDF and doc file from Adobe Reader .This power shell scrip will play very good role to change those Association in windows environment. I have tested this in my testing environment  and it works form me very nicely.





Basically these power shell commands make changes in registry key under "HKLM\SOFTWARE\Classes\.jpeg".This is one of the way to change file association but i found this script do its job very easily.

#################################################################################
#Just save this file .PS1 Extension and run as a admin.

$sFileExts=@("txt","log","csproj","sql","xml","flobble")
echo "## setting up file associations"
foreach ($sFileExts1 in $sFileExts){
    $extfile2=$sFileExts1+"file"
    $dotext="." + $sFileExts1
    cmd /c assoc $dotext=$extfile2
    cmd /c "ftype $extfile2=""C:\Program Files (x86)\Notepad++\notepad++.exe"" %1"
    echo ""
}

#################################################################################


Note:- Please test script in your test environment before running in production directly.

No comments:

Post a Comment