Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $machineName = Read-host "Enter a Machine Name:"
  2. $userName = Read-Host "Enter your admin account:"
  3. $password = Read-Host -AsSecureString "Enter your admin password"
  4. $appName = Read-host "Enter an Application Name:"
  5.  
  6. $Creds = new-object System.Management.Automation.PSCredential -argumentlist $userName,$password
  7.  
  8. $app = Get-WmiObject -Class Win32_Product -computerName $machineName -Credential $Creds | Where-Object {$_.Name -Like $appName}
  9.  
  10. if(($app | Measure-Object).count -eq 0)
  11. {
  12.     Write-Warning "No application called $appName found"
  13. }
  14. Elseif(($app | Measure-Object).count -eq 1)
  15. {
  16.     Write-Host "Application $appname Found, uninstalling...."
  17.     $app.uninstall()
  18. }
  19. Else
  20. {
  21.     Write-Warning "Multiple applications found, please review the list in '$app'"
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement