locked
Powershell application uninstall script RRS feed

  • Question

  • Hello,<o:p></o:p>

    I need a script to uninstall an application.  I have the basis of the script done (see below) but I would like the script to launch a message first saying something along the lines of "uninstalling said application" and when uninstalled I would like it to say "uninstall complete".<o:p></o:p>

    I will be running this as an add package script for a 5.1 app-v package which was originally done as a local install.  The locally installed version needs removed before the virtualised version launches. <o:p></o:p>

    Thanks<o:p></o:p>

    Stephen<o:p></o:p>


    $app = Get-WmiObject -Class Win32_Product | Where-Object {
    $_.Name -match “IntelliVue Clinical Information Portfolio”
    }
    if ($app) {
        $app.Uninstall()
    }


    Monday, September 19, 2016 11:40 AM

Answers

  • Maybe this will help:

    $app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match “IntelliVue Clinical Informaton Portfolio” } if ($app) { [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [System.Windows.Forms.MessageBox]::Show("Uninstalling IntelliVue Clinical Information Portfolio") $app.Uninstall() [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [System.Windows.Forms.MessageBox]::Show("Uninstall complete") }


    If you want to write it to a script window, use:

    $app = Get-WmiObject -Class Win32_Product | Where-Object {
     $_.Name -match “IntelliVue Clinical Informaton Portfolio”
    }
    if ($app) {
    
    
    write-host "Uninstalling IntelliVue Clinical Informaton Portfolio"
    
         $app.Uninstall()
    
    
    
    write-host "Uninstall complete"
    
     }


    Microsoft Application Virtualization 5.1 eBook | Twitter | Blog | App-V Deployment Whitepaper

    If you see a post that helped you please click Vote As Helpful and if it answered your question please click Mark As Answer. This forum post is based upon my personal experience and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

    • Proposed as answer by Hello_2018 Tuesday, September 20, 2016 3:29 AM
    • Marked as answer by Hello_2018 Friday, September 23, 2016 8:03 AM
    Monday, September 19, 2016 2:00 PM
  • Hi Scoop180,

    >>launch a message first saying something along the lines of "uninstalling said application" and when uninstalled I would like it to say "uninstall complete

    There are many ways to do this:

    $VerbosePreference = 'continue'
    $app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match “IntelliVue Clinical Information Portfolio”}
    $prompt = Read-Host -Prompt "Do you want to uninstall the app $($app.name) ?(yes/no)"
    if ($prompt -eq 'yes') {
         Write-Verbose "Begin to uninstall on $($app.name)"
         $app.Uninstall() 
         Write-Host "Uninstalled success!"
     }
     esle
     {
        Write-Host "Cancled!"
     }

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best regards,

    Andy_Pan


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Edited by Hello_2018 Tuesday, September 20, 2016 3:30 AM
    • Marked as answer by Scoop180 Friday, September 23, 2016 7:09 AM
    Tuesday, September 20, 2016 3:28 AM

All replies

  • Maybe this will help:

    $app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match “IntelliVue Clinical Informaton Portfolio” } if ($app) { [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [System.Windows.Forms.MessageBox]::Show("Uninstalling IntelliVue Clinical Information Portfolio") $app.Uninstall() [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [System.Windows.Forms.MessageBox]::Show("Uninstall complete") }


    If you want to write it to a script window, use:

    $app = Get-WmiObject -Class Win32_Product | Where-Object {
     $_.Name -match “IntelliVue Clinical Informaton Portfolio”
    }
    if ($app) {
    
    
    write-host "Uninstalling IntelliVue Clinical Informaton Portfolio"
    
         $app.Uninstall()
    
    
    
    write-host "Uninstall complete"
    
     }


    Microsoft Application Virtualization 5.1 eBook | Twitter | Blog | App-V Deployment Whitepaper

    If you see a post that helped you please click Vote As Helpful and if it answered your question please click Mark As Answer. This forum post is based upon my personal experience and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

    • Proposed as answer by Hello_2018 Tuesday, September 20, 2016 3:29 AM
    • Marked as answer by Hello_2018 Friday, September 23, 2016 8:03 AM
    Monday, September 19, 2016 2:00 PM
  • Hi Scoop180,

    >>launch a message first saying something along the lines of "uninstalling said application" and when uninstalled I would like it to say "uninstall complete

    There are many ways to do this:

    $VerbosePreference = 'continue'
    $app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match “IntelliVue Clinical Information Portfolio”}
    $prompt = Read-Host -Prompt "Do you want to uninstall the app $($app.name) ?(yes/no)"
    if ($prompt -eq 'yes') {
         Write-Verbose "Begin to uninstall on $($app.name)"
         $app.Uninstall() 
         Write-Host "Uninstalled success!"
     }
     esle
     {
        Write-Host "Cancled!"
     }

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best regards,

    Andy_Pan


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Edited by Hello_2018 Tuesday, September 20, 2016 3:30 AM
    • Marked as answer by Scoop180 Friday, September 23, 2016 7:09 AM
    Tuesday, September 20, 2016 3:28 AM
  • Hello,

    Thank you for replying to my post.

    Both solutions work well.

    Regards

    Stephen

    Friday, September 23, 2016 7:09 AM
  • Hello,

    Thank you for replying to my post.

    Both solutions work well.

    Regards

    Stephen

    You're welcome, Stephen.

    Thanks again for your feedback.

    Have a nice day!

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, September 23, 2016 8:02 AM
  • Hi. Can we use echo command instead of write-host command to print text on screen?

    -----------------------------------------------------------------

    Sincerely!

    Khalid Garayev

    * Please don't forget to mark as answer or Vote if it helps!

    Friday, September 23, 2016 9:25 AM
  • Hi. Can we use echo command instead of write-host command to print text on screen?

    -----------------------------------------------------------------

    Sincerely!

    Khalid Garayev

    * Please don't forget to mark as answer or Vote if it helps!

    Of course, we can, Khalid. although it is an old cmdlet.

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, September 23, 2016 9:28 AM
  • Why would you want to use the echo command instead of the write-host command?

    Friday, September 23, 2016 9:34 AM
  • I assume some folks might familiar with the old cmdlet and couldn't adjust for new cmdlet in a short time.

    So, do what they want, as long as the script or codes could give the correct results.

    Agree to differ.

    Have a nice weekend, Scoop180 & Khalid!

    Best regards,

    Andy



    • Edited by Hello_2018 Friday, September 23, 2016 9:57 AM
    Friday, September 23, 2016 9:43 AM
  • for nothing. Just to ensure about my old knowledge :)

    -----------------------------------------------------------------

    Sincerely!

    Khalid Garayev

    * Please don't forget to mark as answer or Vote if it helps!

    Friday, September 23, 2016 11:44 AM
  • Thanks Andy.

    Have a nice week as well.

    Regards

    Stephen

    Friday, September 23, 2016 11:46 AM
  • Just thought I would check in case I was missing something and one was more beneficial to use than the other.

    Regards

    Stephen

    Friday, September 23, 2016 11:48 AM
  • Hi. Can we use echo command instead of write-host command to print text on screen?

    -----------------------------------------------------------------

    Sincerely!

    Khalid Garayev

    * Please don't forget to mark as answer or Vote if it helps!

    In PowerShell echo is just an alias for Write-Output.


    Friday, September 23, 2016 12:10 PM