This topic contains 2 replies, has 2 voices, and was last updated by
May 13, 2013 at 3:59 pm #4684ParticipantPoints: 0Rank: Member
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
2. 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%'"
3. 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()
4. 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.
May 14, 2013 at 4:46 pm #4810KeymasterPoints: 1,811Rank: Community Hero
Not a terribly useful error.
Try doing this without Remoting, if you can. Get-WmiObject is capable of connecting to a remote computer. Pipe the result to Invoke-WmiMethod, giving it method name Uninstall. That might remove a layer or two and get a better error message, if nothing else.
May 15, 2013 at 7:06 am #4849ParticipantPoints: 0Rank: Member
I tried to pipe the result to Invoke-WmiMethod like this:
$app = Get-WmiObject -Class Win32_Product -Filter "Name LIKE 'AppUnderTest%'" | Invoke-WmiMethod $app.Uninstall()
I got a prompt asking me for a WmiMethod, I entered "Uninstall"
The command completed without error but my app was not uninstalled. I have a feeling I'm not piping it correctly.
The topic ‘Uninstall working but returning an error in PS Console’ is closed to new replies.