IIT.UpdateNppPlugins.psm1

function Update-NPPPlugins
{
<#
    Created by Andrej Licar, IIT
 
    .Synopsis
            Updates Notepad++ after updating to 7.6.x
 
    .Description
            Updates the Notepad++ plugins' locations after application was updated to a version 7.6.x and deletes the leftover old plugins when a new version is already in place.
 
    .Notes
            Module name: Update-NPPPlugins
            Version: 1.0
            Author: Andrej Licar
            Contact: info@iit.si
            DateCreated: 2019-01-10
            LastUpdate: 2019-01-10
         
    .Version
            1.0 : Initial release - 2019/01/10
 
    .Inputs
            System.String
             
            Takes a folder name where plugins of the Notepad++ are located.
 
    .Outputs
            Nothing.
 
    .Parameter Path
            Full Path to the plugins folder of the Notepad++ installation.
 
    .Example
            Update-NPPPlugins "$($env:ProgramData)\Notepad++\Plugins"
             
            -----------
            Description
            Updates the plugins in the ProgramData\Notepad++\Plugins folder.
     
 
    .Example
            Update-NPPPlugins "$(${env:ProgramFiles(x86)})\Notepad++\Plugins"
 
            -----------
            Description
            Updates the plugins in the \ProgramFiles(x86)\Notepad++\Plugins folder
            i.e. 32-bit Notepad++ installation on 64-bit computer
             
    .Example
            Update-NPPPlugins "C:\Notepad++\Plugins"
 
            -----------
            Description
            Updates the plugins in the literal path C:\Notepad++\Plugins folder
             
             
    #>

    [CmdletBinding(SupportsShouldProcess=$True)]
    param(
        [Parameter(
            Position=0,
            ValueFromPipeline=$true,
            ValueFromPipelineByPropertyName=$true,
            HelpMessage="Notepad++ plugin path.",
            Mandatory=$true
        )]
        [string]$Path
        )

        # test if we should really process the plugins
        if ($PSCmdlet.ShouldProcess($Path, "Update plugins after updating Notepad++ version from 7.5.x to 7.6.x"))
        {
                # fail-safe get the path object from the supplied path
                Get-Item -Path $Path | out-null
                
                # test if path object was ok and name is plugins
                if ($p.Name -eq "Plugins") {

                        # test if the nppPluginList.dll exists in the Config subfolder
                        Get-Item -Path "$($Path)\Config\nppPluginList.dll" | out-null
                        
                        # get all dll files in the plugins folder and loop through the list
                        Get-Item -Path "$($Path)\*.dll" | ForEach-Object
                        {
                                # copy the item name to a variable (not necessary, but looks nicer :) )
                                $name = $_

                                Try
                                {
                                        # create a new folder with the same name as the plugin DLL (without extension, hence the basename)
                                        $res = New-Item -Path $name.DirectoryName -Name $name.BaseName -ItemType Directory
                                }
                                Catch
                                {
                                        # don't nag, folder already exists -> probably a new version of plugin is already there
                                }
                                Try
                                {
                                        # move the plugin dll to the newly created folder
                                        $res = Move-Item -Path $name -Destination "$($name.DirectoryName)\$($name.BaseName)\"

                                }
                                Catch
                                {
                                        # we can safely delete the old plugin dll, since the file already exists
                                        $res = Remove-Item -Path $name
                                }
                        }
                }
        }
}

New-Alias -Name "unppp" -Value "Update-NPPPlugins"

Export-ModuleMember -Function "Update-NPPPlugins" -Alias "unppp"