Skip to content

Commit 0c7fc4d

Browse files
committed
Support uninstalling unity setup instances
1 parent d1c6ba8 commit 0c7fc4d

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
@@ -365,6 +365,51 @@ function Install-UnitySetupInstance
365365
}
366366
}
367367

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

0 commit comments

Comments
 (0)