I have one application to replace another application. The install seems to work fine (mostly). The problem is the uninstall of the 2nd application. There are (at least) 4 different versions that require 4 separate uninstall commands in order to run.<\/p>\n

Advertisement

So, please see the below code with comments:<\/p>","upvoteCount":5,"answerCount":11,"datePublished":"2019-09-13T19:12:54.000Z","author":{"@type":"Person","name":"cvn65-weaps","url":"https://community.spiceworks.com/u/cvn65-weaps"},"acceptedAnswer":{"@type":"Answer","text":"

\n
\n
<\/div>\n\"\" CVN65-WEAPS:<\/div>\n
\n
Advertisement

There are (at least) 4 different versions that require 4 separate uninstall commands in order to run.<\/p>\n<\/blockquote>\n<\/aside>\n

i’d look into a switch statement<\/p>\n

$version = # code to get version\n\nswitch($version){\n    '1.2'{ <#Code to remove version 1.2#>}\n    '1.4'{ <#Code to remove version 1.4#>}\n    '1.5'{ <#Code to remove version 1.5#>}\n    default { <# code if none of the versions match#>}\n}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2019-09-13T19:20:37.000Z","url":"https://community.spiceworks.com/t/else-statement-skips-and-test-path-does-not-match-up/730023/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},"suggestedAnswer":[{"@type":"Answer","text":"

I have one application to replace another application. The install seems to work fine (mostly). The problem is the uninstall of the 2nd application. There are (at least) 4 different versions that require 4 separate uninstall commands in order to run.<\/p>\n

So, please see the below code with comments:<\/p>","upvoteCount":5,"datePublished":"2019-09-13T19:12:54.000Z","url":"https://community.spiceworks.com/t/else-statement-skips-and-test-path-does-not-match-up/730023/1","author":{"@type":"Person","name":"cvn65-weaps","url":"https://community.spiceworks.com/u/cvn65-weaps"}},{"@type":"Answer","text":"

#Section<\/span> 4
\n$AppService = “C:\\Program Files\\Application\\ApplicationService.exe”
\n$AppServiceExists = Test-Path $AppService<\/p>\n

If ($AppServiceExists -eq $True) {Add-Content \\FileShare\\ApplicationLogs$COMPUTERNAME.log “Application Exists”
\n}else
\n{
\nAdd-Content \\FileShare\\ApplicationLogs$COMPUTERNAME.log “Application Does not exist”
\ncmd.exe /c \\FileShare\\Application\\Application.exe /install /quiet /norestart
\n}<\/p>\n

If ($AppServiceExists -eq $True) {Add-Content \\FileShare\\ApplicationLogs$COMPUTERNAME.log “Application Installed”
\n}Else
\n{
\nAdd-Content \\FileShare\\ApplicationLogs$COMPUTERNAME.log “Check install of Application” #This<\/span> was logged. A - I need to retest with Test-Path… Easy enough.<\/strong>
\nExit-PSSession #B<\/span> - The session should have exited here (since I did not retest with Test-Path). Instead, it continued on to Section 5. This is a problem as I need it to stop here if there is an error.<\/strong>
\n}<\/p>\n

#Section<\/span> 5<\/p>\n

$SEP1 = “{F90EEB64-A4CB-484A-8666-812D9F92B37B}” #v12<\/span>.1.7004.6500
\n$SEP2 = “{0E251D4D-316C-4F8B-A4C5-2722000764BE}” #v12<\/span>.1.5337.5000
\n$SEP3 = “{3DCB7A99-79F6-4FC5-93F4-55DB5D275F12}” #v14<\/span>.0.2415.0200
\n$SEP4 = “{F6EE99BF-78F2-479F-B3A0-B6D7F55EC53B}” #v14<\/span>.2.x
\n$SEP = (Get-WMIObject win32_Product).IdentifyingNumber
\n$SEPInstalled = Test-Path $SEP<\/p>\n

If ($SEPInstalled -eq $SEP1) {Add-Content “\\FileShare\\ApplicationLogs$COMPUTERNAME Symantec.log” “SEP v12.1.7004.6500 is installed”
\ncmd.exe /c “MsiExec.exe /qn /norestart /X{F90EEB64-A4CB-484A-8666-812D9F92B37B}”
\nAdd-Content “\\FileShare\\ApplicationLogs$COMPUTERNAME Symantec.log” “SEP v12.1.7004.6500 uninstalled”<\/p>\n

}ElseIF ($SEPInstalled -eq $SEP2) {Add-Content “\\FileShare\\ApplicationLogs$COMPUTERNAME Symantec.log” “SEP v12.1.5337.5000 is installed”
\ncmd.exe /c “MsiExec.exe /qn /norestart /X{0E251D4D-316C-4F8B-A4C5-2722000764BE}”
\nAdd-Content “\\FileShare\\ApplicationLogs$COMPUTERNAME Symantec.log” “SEP v12.1.5337.5000 uninstalled”
\n#The<\/span> below version is installed. This was skipped over.<\/strong>
\n}ElseIF ($SEPInstalled -eq $SEP3) {Add-Content “\\FileShare\\ApplicationLogs$COMPUTERNAME Symantec.log” “SEP v14.0.2415.0200 is installed”
\ncmd.exe /c “MsiExec.exe /qn /norestart /X{3DCB7A99-79F6-4FC5-93F4-55DB5D275F12}”
\nAdd-Content “\\FileShare\\ApplicationLogs$COMPUTERNAME Symantec.log” “SEP v14.0.2415.0200 uninstalled”<\/p>\n

}ElseIF ($SEPInstalled -eq $SEP4) {Add-Content “\\FileShare\\ApplicationLogs$COMPUTERNAME Symantec.log” “SEP v14.2 is installed”
\ncmd.exe /c “MsiExec.exe /qn /norestart /X{F6EE99BF-78F2-479F-B3A0-B6D7F55EC53B}”
\nAdd-Content “\\FileShare\\ApplicationLogs$COMPUTERNAME Symantec.log” “SEP v14.2 uninstalled”
\n}Else {Add-Content “\\FileShare\\ApplicationLogs$COMPUTERNAME Symantec.log” “Symantec EndPoint Protection is not installed” #This<\/span> was logged. Should have uninstalled above.<\/strong><\/p>","upvoteCount":0,"datePublished":"2019-09-13T19:13:46.000Z","url":"https://community.spiceworks.com/t/else-statement-skips-and-test-path-does-not-match-up/730023/2","author":{"@type":"Person","name":"cvn65-weaps","url":"https://community.spiceworks.com/u/cvn65-weaps"}},{"@type":"Answer","text":"

If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n

PLEASE READ BEFORE POSTING! Read if you're new to the PowerShell forum!<\/a> .<\/p>\n

\"codebutton_small.png\"<\/p>","upvoteCount":0,"datePublished":"2019-09-13T19:17:50.000Z","url":"https://community.spiceworks.com/t/else-statement-skips-and-test-path-does-not-match-up/730023/3","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"

Thanks. I’ll give that a shot. I attempted to post the code. Missed the “Language” part (Defaulted to English, so I didn’t check it.)<\/p>","upvoteCount":0,"datePublished":"2019-09-13T19:39:15.000Z","url":"https://community.spiceworks.com/t/else-statement-skips-and-test-path-does-not-match-up/730023/5","author":{"@type":"Person","name":"cvn65-weaps","url":"https://community.spiceworks.com/u/cvn65-weaps"}},{"@type":"Answer","text":"

This mostly worked:<\/p>\n

Symantec EndPoint Protection is not installed
\nSymantec EndPoint Protection is not installed
\nSymantec EndPoint Protection is not installed
\nSymantec EndPoint Protection is not installed
\nSEP v14.0.2415.0200 uninstalled
\nSymantec EndPoint Protection is not installed<\/p>\n

(The code insert still isn’t working for me…)<\/p>","upvoteCount":0,"datePublished":"2019-09-13T20:00:24.000Z","url":"https://community.spiceworks.com/t/else-statement-skips-and-test-path-does-not-match-up/730023/6","author":{"@type":"Person","name":"cvn65-weaps","url":"https://community.spiceworks.com/u/cvn65-weaps"}},{"@type":"Answer","text":"

$SEP1 = “{F90EEB64-A4CB-484A-8666-812D9F92B37B}” #v12<\/span>.1.7004.6500
\n$SEP2 = “{0E251D4D-316C-4F8B-A4C5-2722000764BE}” #v12<\/span>.1.5337.5000
\n$SEP3 = “{3DCB7A99-79F6-4FC5-93F4-55DB5D275F12}” #v14<\/span>.0.2415.0200
\n$SEP4 = “{F6EE99BF-78F2-479F-B3A0-B6D7F55EC53B}” #v14<\/span>.2.x
\n$SEP = (Get-WMIObject win32_Product).IdentifyingNumber
\n#$SEPInstalled = Test-Path $SEP<\/p>\n

switch($SEP){
\n$SEP1{cmd.exe /c “MsiExec.exe /qn /norestart /X{F90EEB64-A4CB-484A-8666-812D9F92B37B}”
\nAdd-Content “\\FileShare\\ApplicationLogs$COMPUTERNAME Symantec.log” “SEP v12.1.7004.6500 uninstalled”}
\n$SEP2{cmd.exe /c “MsiExec.exe /qn /norestart /X{0E251D4D-316C-4F8B-A4C5-2722000764BE}”
\nAdd-Content “\\FileShare\\ApplicationLogs$COMPUTERNAME Symantec.log” “SEP v12.1.5337.5000 uninstalled”}
\n$SEP3{cmd.exe /c “MsiExec.exe /qn /norestart /X{3DCB7A99-79F6-4FC5-93F4-55DB5D275F12}”
\nAdd-Content “\\FileShare\\ApplicationLogs$COMPUTERNAME Symantec.log” “SEP v14.0.2415.0200 uninstalled”}
\n$SEP4{cmd.exe /c “MsiExec.exe /qn /norestart /X{F6EE99BF-78F2-479F-B3A0-B6D7F55EC53B}”
\nAdd-Content “\\FileShare\\ApplicationLogs$COMPUTERNAME Symantec.log” “SEP v14.2 uninstalled”}
\ndefault {Add-Content “\\FileShare\\ApplicationLogs$COMPUTERNAME Symantec.log” “Symantec EndPoint Protection is not installed”}<\/p>","upvoteCount":0,"datePublished":"2019-09-13T20:03:06.000Z","url":"https://community.spiceworks.com/t/else-statement-skips-and-test-path-does-not-match-up/730023/7","author":{"@type":"Person","name":"cvn65-weaps","url":"https://community.spiceworks.com/u/cvn65-weaps"}},{"@type":"Answer","text":"

have you tried a different browser?<\/p>\n

That looks much cleaner, does that work now?<\/p>","upvoteCount":0,"datePublished":"2019-09-13T20:10:13.000Z","url":"https://community.spiceworks.com/t/else-statement-skips-and-test-path-does-not-match-up/730023/8","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"

No. That was a copy/paste directly.<\/p>","upvoteCount":0,"datePublished":"2019-09-13T21:48:43.000Z","url":"https://community.spiceworks.com/t/else-statement-skips-and-test-path-does-not-match-up/730023/9","author":{"@type":"Person","name":"cvn65-weaps","url":"https://community.spiceworks.com/u/cvn65-weaps"}},{"@type":"Answer","text":"

Did you try to invoke the cmd command?<\/p>\n

\n
\n\n learn.microsoft.com<\/a>\n <\/header>\n\n
\n \n\n

Invoke-Command (Microsoft.PowerShell.Core) - PowerShell<\/a><\/h3>\n\n

The Invoke-Command cmdlet runs commands on a local or remote computer and returns all output from the commands, including errors. Using a single Invoke-Command command, you can run commands on multiple computers. To run a single command on a remote...<\/p>\n\n\n <\/article>\n\n

\n \n \n <\/div>\n\n
<\/div>\n<\/aside>\n","upvoteCount":0,"datePublished":"2019-09-16T05:11:31.000Z","url":"https://community.spiceworks.com/t/else-statement-skips-and-test-path-does-not-match-up/730023/10","author":{"@type":"Person","name":"holgerstaiger2","url":"https://community.spiceworks.com/u/holgerstaiger2"}},{"@type":"Answer","text":"
\n
\n
<\/div>\n\"\" Neally:<\/div>\n
\n

have you tried a different browser?<\/p>\n

That looks much cleaner, does that work now?<\/p>\n<\/blockquote>\n<\/aside>\n

I may have mis-read this. Yes, this portion now works.<\/p>\n

The only portion not working is the Exit-PSSession. I just changed it to (simply) Exit and it now appears to work properly.<\/p>\n

Thanks all!<\/p>","upvoteCount":0,"datePublished":"2019-09-16T13:28:25.000Z","url":"https://community.spiceworks.com/t/else-statement-skips-and-test-path-does-not-match-up/730023/11","author":{"@type":"Person","name":"cvn65-weaps","url":"https://community.spiceworks.com/u/cvn65-weaps"}}]}}