Skip to content

Commit 04c908f

Browse files
authored
Merge pull request #39 from jwittner/dev/uninstall
Support uninstalling unity setup instances
2 parents bc8f840 + 0c7fc4d commit 04c908f

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

UnitySetup/UnitySetup.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ FunctionsToExport = @(
7979
'Get-UnitySetupInstance',
8080
'Install-UnitySetupInstance',
8181
'Select-UnitySetupInstance',
82+
'Uninstall-UnitySetupInstance',
8283
'Start-UnityEditor'
8384
)
8485
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.

UnitySetup/UnitySetup.psm1

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,51 @@ function Install-UnitySetupInstance
370370
}
371371
}
372372

373+
<#
374+
.Synopsis
375+
Uninstall Unity Setup Instances
376+
.DESCRIPTION
377+
Uninstall the specified Unity Setup Instances
378+
.PARAMETER Instance
379+
What instances of UnitySetup should be uninstalled
380+
.EXAMPLE
381+
Get-UnitySetupInstance | Uninstall-UnitySetupInstance
382+
#>
383+
function Uninstall-UnitySetupInstance {
384+
[CmdletBinding(SupportsShouldProcess)]
385+
param(
386+
[parameter(Mandatory = $true, ValueFromPipeline = $true)]
387+
[UnitySetupInstance[]] $Instances
388+
)
389+
390+
process {
391+
foreach ( $setupInstance in $Instances ) {
392+
$uninstaller = Get-ChildItem "$($setupInstance.Path)" -Filter 'Uninstall.exe' -Recurse |
393+
Select-Object -First 1 -ExpandProperty FullName
394+
395+
if($null -eq $uninstaller) {
396+
Write-Error "Could not find Uninstaller.exe under $($setupInstance.Path)"
397+
continue
398+
}
399+
400+
$startProcessArgs = @{
401+
'FilePath' = $uninstaller;
402+
'PassThru' = $true;
403+
'Wait' = $true;
404+
'ErrorAction' = 'Stop';
405+
'ArgumentList' = @("/S");
406+
}
407+
408+
if( -not $PSCmdlet.ShouldProcess("$uninstaller", "Start-Process")) { continue }
409+
410+
$process = Start-Process @startProcessArgs
411+
if ( $process.ExitCode -ne 0 ) {
412+
Write-Error "Uninstaller quit with non-zero exit code"
413+
}
414+
}
415+
}
416+
}
417+
373418
<#
374419
.Synopsis
375420
Get the Unity versions installed

0 commit comments

Comments
 (0)