Skip to content

Support uninstalling unity setup instances #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UnitySetup/UnitySetup.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ FunctionsToExport = @(
'Get-UnitySetupInstance',
'Install-UnitySetupInstance',
'Select-UnitySetupInstance',
'Uninstall-UnitySetupInstance',
'Start-UnityEditor'
)
# 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.
Expand Down
45 changes: 45 additions & 0 deletions UnitySetup/UnitySetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,51 @@ function Install-UnitySetupInstance
}
}

<#
.Synopsis
Uninstall Unity Setup Instances
.DESCRIPTION
Uninstall the specified Unity Setup Instances
.PARAMETER Instance
What instances of UnitySetup should be uninstalled
.EXAMPLE
Get-UnitySetupInstance | Uninstall-UnitySetupInstance
#>
function Uninstall-UnitySetupInstance {
[CmdletBinding(SupportsShouldProcess)]
param(
[parameter(Mandatory = $true, ValueFromPipeline = $true)]
[UnitySetupInstance[]] $Instances
)

process {
foreach ( $setupInstance in $Instances ) {
$uninstaller = Get-ChildItem "$($setupInstance.Path)" -Filter 'Uninstall.exe' -Recurse |
Select-Object -First 1 -ExpandProperty FullName

if($null -eq $uninstaller) {
Write-Error "Could not find Uninstaller.exe under $($setupInstance.Path)"
continue
}

$startProcessArgs = @{
'FilePath' = $uninstaller;
'PassThru' = $true;
'Wait' = $true;
'ErrorAction' = 'Stop';
'ArgumentList' = @("/S");
}

if( -not $PSCmdlet.ShouldProcess("$uninstaller", "Start-Process")) { continue }

$process = Start-Process @startProcessArgs
if ( $process.ExitCode -ne 0 ) {
Write-Error "Uninstaller quit with non-zero exit code"
}
}
}
}

<#
.Synopsis
Get the Unity versions installed
Expand Down