diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..620976d --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +/Uninstall.psm1 -text +/MiniModules.Uninstall.psd1 text eol=lf +/Uninstall*.Tests.ps1 text eol=lf +/Uninstall.md text eol=lf +/LICENSE text eol=lf +/out/* text eol=lf +/out/Uninstall.psm1 -text diff --git a/.github/workflows/source-uninstall.yml b/.github/workflows/source-uninstall.yml new file mode 100644 index 0000000..b40ed83 --- /dev/null +++ b/.github/workflows/source-uninstall.yml @@ -0,0 +1,15 @@ +name: Uninstall source checks +on: + push: + branches: [prepare/uninstall-package] + pull_request: + branches: [Uninstall/develop] +permissions: + contents: read +jobs: + source: + uses: stadub/PowershellScripts/.github/workflows/validate-module-source.yml@42814913be33a4662a57dbf011333b96c5fa294f + with: + module: Uninstall + source_sha: ${{ github.event.pull_request.head.sha || github.sha }} + automation_sha: 42814913be33a4662a57dbf011333b96c5fa294f diff --git a/MiniModules.Uninstall.psd1 b/MiniModules.Uninstall.psd1 new file mode 100644 index 0000000..f045088 --- /dev/null +++ b/MiniModules.Uninstall.psd1 @@ -0,0 +1,20 @@ +@{ + RootModule = 'Uninstall.psm1' + ModuleVersion = '1.0.1' + GUID = '27c80b64-2c07-43ee-ae20-4d94965295eb' + Author = 'Dima Stadub' + Description = 'Windows application uninstall helper using the registry and msiexec. Importing the module does not uninstall applications.' + PowerShellVersion = '5.1' + FunctionsToExport = @('Uninstall-Application') + CmdletsToExport = @() + VariablesToExport = @() + AliasesToExport = @() + PrivateData = @{ + PSData = @{ + Tags = @('Windows', 'Uninstall', 'msiexec') + LicenseUri = 'https://github.com/stadub/PowershellScripts/blob/master/LICENSE' + ProjectUri = 'https://github.com/stadub/PowershellScripts' + ReleaseNotes = 'Prepare the existing standalone module for manifest-based packaging; uninstall implementation unchanged.' + } + } +} diff --git a/Uninstall.Tests.ps1 b/Uninstall.Tests.ps1 new file mode 100644 index 0000000..2f3210b --- /dev/null +++ b/Uninstall.Tests.ps1 @@ -0,0 +1,29 @@ +$manifest = Join-Path $PSScriptRoot 'MiniModules.Uninstall.psd1' +Describe 'Uninstall module packaging contracts' { + BeforeAll { + $script:loaded = Import-Module $manifest -Force -PassThru -ErrorAction Stop + } + AfterAll { Remove-Module $script:loaded -Force -ErrorAction SilentlyContinue } + It 'validates the manifest and unchanged public command' { + (Test-ModuleManifest $manifest).Version.ToString() | Should -BeExactly '1.0.1' + $script:loaded.Name | Should -BeExactly 'MiniModules.Uninstall' + (Import-PowerShellDataFile $manifest).RootModule | Should -BeExactly 'Uninstall.psm1' + $script:loaded.ExportedFunctions.Count | Should -Be 1 + $script:loaded.ExportedFunctions.ContainsKey('Uninstall-Application') | Should -BeTrue + } + It 'preserves the mandatory pipeline software-name parameter and Application alias' { + $command = $script:loaded.ExportedFunctions['Uninstall-Application'] + $parameter = $command.Parameters['SoftwareName'] + $parameter.Aliases | Should -Contain 'Application' + $contract = @($parameter.Attributes | Where-Object { $_ -is [Management.Automation.ParameterAttribute] })[0] + $contract.Mandatory | Should -BeTrue + $contract.ValueFromPipeline | Should -BeTrue + } + It 'imports safely without starting an uninstaller or reading registry entries' { + Mock Start-Process { throw 'Unexpected uninstaller invocation' } + Mock Get-ItemProperty { throw 'Unexpected registry access' } + Import-Module $manifest -Force -ErrorAction Stop + Assert-MockCalled Start-Process 0 -Exactly -Scope It + Assert-MockCalled Get-ItemProperty 0 -Exactly -Scope It + } +} diff --git a/Uninstall.md b/Uninstall.md new file mode 100644 index 0000000..18558d6 --- /dev/null +++ b/Uninstall.md @@ -0,0 +1,16 @@ +# MiniModules.Uninstall module preparation + +The owner-approved MiniModules.Uninstall 1.0.1 manifest wraps the existing Uninstall.psm1 without changing its +implementation. Importing it exports Uninstall-Application and performs no +uninstall operation. Execution requires Windows registry/msiexec facilities. + +The Gallery name Uninstall currently refers to an unlisted script owned by +DimaStadub, not one of the configured Stadub/MiniModules module routes. The new module uses the distinct +MiniModules.Uninstall name and the owner-selected MiniModules account; it does not +replace, relist or claim that legacy script. +No Gallery upload, relisting, ownership transfer or uninstall was performed. + +The package contains only the module, manifest, this document and the existing +repository BSD-2-Clause LICENSE. It must never include unrelated monorepo files. +Tests cover safe import and the public parameter contract; actual registry lookup +and software removal remain unvalidated legacy behavior. diff --git a/out/LICENSE b/out/LICENSE new file mode 100644 index 0000000..714075e --- /dev/null +++ b/out/LICENSE @@ -0,0 +1,25 @@ +BSD 2-Clause License + +Copyright (c) 2019, Dima Stadub +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/out/MiniModules.Uninstall.psd1 b/out/MiniModules.Uninstall.psd1 new file mode 100644 index 0000000..f045088 --- /dev/null +++ b/out/MiniModules.Uninstall.psd1 @@ -0,0 +1,20 @@ +@{ + RootModule = 'Uninstall.psm1' + ModuleVersion = '1.0.1' + GUID = '27c80b64-2c07-43ee-ae20-4d94965295eb' + Author = 'Dima Stadub' + Description = 'Windows application uninstall helper using the registry and msiexec. Importing the module does not uninstall applications.' + PowerShellVersion = '5.1' + FunctionsToExport = @('Uninstall-Application') + CmdletsToExport = @() + VariablesToExport = @() + AliasesToExport = @() + PrivateData = @{ + PSData = @{ + Tags = @('Windows', 'Uninstall', 'msiexec') + LicenseUri = 'https://github.com/stadub/PowershellScripts/blob/master/LICENSE' + ProjectUri = 'https://github.com/stadub/PowershellScripts' + ReleaseNotes = 'Prepare the existing standalone module for manifest-based packaging; uninstall implementation unchanged.' + } + } +} diff --git a/out/Uninstall.md b/out/Uninstall.md new file mode 100644 index 0000000..18558d6 --- /dev/null +++ b/out/Uninstall.md @@ -0,0 +1,16 @@ +# MiniModules.Uninstall module preparation + +The owner-approved MiniModules.Uninstall 1.0.1 manifest wraps the existing Uninstall.psm1 without changing its +implementation. Importing it exports Uninstall-Application and performs no +uninstall operation. Execution requires Windows registry/msiexec facilities. + +The Gallery name Uninstall currently refers to an unlisted script owned by +DimaStadub, not one of the configured Stadub/MiniModules module routes. The new module uses the distinct +MiniModules.Uninstall name and the owner-selected MiniModules account; it does not +replace, relist or claim that legacy script. +No Gallery upload, relisting, ownership transfer or uninstall was performed. + +The package contains only the module, manifest, this document and the existing +repository BSD-2-Clause LICENSE. It must never include unrelated monorepo files. +Tests cover safe import and the public parameter contract; actual registry lookup +and software removal remain unvalidated legacy behavior. diff --git a/out/Uninstall.psm1 b/out/Uninstall.psm1 new file mode 100644 index 0000000..eae6c3e --- /dev/null +++ b/out/Uninstall.psm1 @@ -0,0 +1,81 @@ + +<#PSScriptInfo + +.VERSION 1.0 + +.GUID 27c80b64-2c07-43ee-ae20-4d94965295eb + +.AUTHOR Dima Stadub + +.COMPANYNAME + +.COPYRIGHT + +.TAGS uninstall msiexec + +.LICENSEURI + +.PROJECTURI https://github.com/stadub/PowershellScripts + +.ICONURI + +.EXTERNALMODULEDEPENDENCIES + +.REQUIREDSCRIPTS + +.EXTERNALSCRIPTDEPENDENCIES + +.RELEASENOTES + + +#> + + +<# +.SYNOPSIS + Uninstall Application +.DESCRIPTION + Allows to Uninstall Application from system +.EXAMPLE + Uninstall-Application "Microsoft*4.5*" +.PARAMETER SoftwareName + Application name(Or application name format) +#> + + +function Uninstall-Application { +param( + + [Parameter(Mandatory=$True, ValueFromPipeline=$True, + ValueFromPipelineByPropertyName=$True, HelpMessage='Enter the Application to uninstall.')] + [Alias('Application')] + [string] $SoftwareName + +) + +$uninstallX86RegPath="HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" +$uninstallX64RegPath="HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" + +$uninstallString="" + +$uninstall32 = gci $(uninstallX64RegPath) | foreach { gp $_.PSPath } | ? { $_ -like $SoftwareName } | select UninstallString +$uninstall64 = gci $(uninstallX86RegPath) | foreach { gp $_.PSPath } | ? { $_ -like $SoftwareName } | select UninstallString + +if($uninstall64) {$uninstallString=$uninstall64;} +if($uninstall32) {$uninstallString=$uninstall32;} + +if(!$uninstallString) { + Write-Error "Application was is not found" +} + + +$uninstallString = $uninstallString.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X","" +$uninstallString = $uninstallString.Trim() +Write "Uninstalling..." + +start-process "msiexec.exe" -arg "/X $uninstallString /qb" -Wait + +} + + +export-modulemember -function Uninstall-Application