I just started using Powershell for the first time last week. I’m the only one in my office that knows has started to use Powershell and I need to be able to do a lot with it in a short amount of time.
Today I got Powershell working so that I could start a new pssession with a remote computer (so satisfying when it finally worked ). I wanted to start out by just uninstalling a test version of an application so that I can reinstall the latest version. I got the application uninstalled but Powershell returned an error and I don’t know why and it’s bothering me.
So… here are my steps:
1.Â I entered my PSSession with my test computer:
Enter-PSSession JosiahTest -Credential JosiahTest\johnnydepp
- I created a variable called $app and assigned that variable to the result of a WmiObject -Class Win32_Product query:
$app = Get-WmiObject -Class Win32_Product -Filter "Name LIKE 'AppUnderTest%'"
- I realized that while I did successfully get the application I was looking for I forgot to uninstall it so I did this:
$app = Get-WmiObject -Class Win32_Product -Filter "Name LIKE 'AppUnderTest%'" $app.Uninstall()
- I waited for awhile, the script seemed to be working, I was refreshing my ‘Add or Remove’ programs window on my test system and much to my satisfaction the AppUnderTest was removed! Unfortunately about a minute later Powershell returned this:
Get-WmiObject : Invalid query At line:1 char:21 + $app = Get-WmiObject <<<< -Class Win32_Product -Filter "Name LIKE 'AppUnderTest%'" $app.Uninstall() + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementExc eption + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Comma nds.GetWmiObjectCommand
I feel like I was so close, then I got an error… What have I done wrong? It looks like a valid query, it uninstalled the program, but for some reason I still got an error.