NiCE Library Uninstall MSI remotely WriteAction

NiCE.Library.W.Uninstall.MSI.Remotely.WA (WriteActionModuleType)

WriteAction to copy msi to remote temp using unc path and run de-installation.

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.BaseData

Member Modules:

ID Module Type TypeId RunAs 
InstallMSI WriteAction Microsoft.Windows.PowerShellWriteAction Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TargetSystemstring$Config/TargetSystem$Target SystemFQDN of the target computer.

Source Code:

<WriteActionModuleType ID="NiCE.Library.W.Uninstall.MSI.Remotely.WA" Accessibility="Public" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TargetSystem" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="MSISourcePath" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="MSISourcePathX64" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TargetSystem" Selector="$Config/TargetSystem$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="InstallMSI" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>NiCEInstallMSIRemote.ps1</ScriptName>
<ScriptBody><Script>Param(
[string]$TargetSystem,
[string]$MSISourcePath,
[string]$MSISourcePathX64,
[string]$InstallDirectory,
[string]$Uninstall
)

If($TargetSystem)
{
#Create Remote Session on target computer
$session = New-PSSession -ComputerName $TargetSystem

#Get temp from remote system
$RemoteTemp = Invoke-Command -Session $session -ScriptBlock {$env:TEMP} | % {$_ -replace ':','$'}
$Bitness = (Get-WmiObject Win32_OperatingSystem -computername $TargetSystem).OSArchitecture

#$RemoteTemp
#$Bitness
#$MSISourcePath
#$MSISourcePathX64
#$InstallDirectory

#Copy MSI to remote temp directory using unc path
If ($Bitness -eq '64-bit' -and $MSISourcePathX64)
{
Copy-Item -path "$MSISourcePathX64" -Destination "\\$TargetSystem\$RemoteTemp\Instrumentation.msi"
}
else
{
Copy-Item -path "$MSISourcePath" -Destination "\\$TargetSystem\$RemoteTemp\Instrumentation.msi"
}

$Installmode = "/i"
if($Uninstall)
{
$Installmode = "/x"
}

#Prepare msi arguments
$arguments = @(
"$Installmode"
"`"Instrumentation.msi`""
"/quiet"
"/norestart"
"/log"
"`"Instrumentation.log`""
)

#Add install directory if provided
if ($InstallDirectory)
{
$arguments += "INSTALLDIR=`"$InstallDirectory`""
}

#Prepare ScriptBlock
$sb = {
Set-Location -Path $env:TEMP

$process = Start-Process -WorkingDirectory "$env:TEMP" -FilePath msiexec.exe -ArgumentList $using:arguments -Wait -PassThru

if ($process.ExitCode -eq 0)
{
If($using:Uninstall)
{
Write-Host "Deinstallation was successfully."
}
else
{
Write-Host "Installation was successfully."
}
}
else
{
Write-Host "Installer exit code $($process.ExitCode)`n"
Get-Content -Path "Instrumentation.log"
}

Remove-Item -Path "$env:TEMP\Instrumentation.msi"
Remove-Item -Path "$env:TEMP\Instrumentation.log"
}

#Run installation and cleanup
Invoke-Command -Session $session -ScriptBlock $sb

#Remove opened remote session
Remove-PSSession -Session $session
}
else
{
Write-Host "Empty target system, please provide computer name as override."
}</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>TargetSystem</Name>
<Value>$Config/TargetSystem$</Value>
</Parameter>
<Parameter>
<Name>MSISourcePath</Name>
<Value>$Config/MSISourcePath$</Value>
</Parameter>
<Parameter>
<Name>MSISourcePathX64</Name>
<Value>$Config/MSISourcePathX64$</Value>
</Parameter>
<Parameter>
<Name>Uninstall</Name>
<Value>True</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>600</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="InstallMSI"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.BaseData</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>