TechTalkz.com Logo Ask the Experts!

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Microsoft > Microsoft Windows Powershell

Get-WmiObject : Generic Failure

Microsoft Windows Powershell

 
 
Thread Tools Display Modes
Unread 26-02-2008, 10:20 AM   #1
Mel
Guest
 
Posts: n/a
Get-WmiObject : Generic Failure

Hi, I am trying to use PowerShell and WMI to uninstall a msi from a remote
machine. I have no problem installing with WMI but cannot uninstall. I think
it is a permissions issue but I am not sure.

My issue is simple to reproduce.

$strComputer = "MachineName.Domain.ie"
$processes = Get-WmiObject -Class Win32_Process -ComputerName $strComputer
$products = Get-WmiObject -Class Win32_Product -ComputerName $strComputer

The first call with Win32_Process runs without problem. These second to
Win32_Product does not. It returns the "Generic Failure" error message. I am
using WinXP and trying to connect to Windows Server 2003. I am an admin on
both machines. I have noticed that if I am logged into the server with
Remote Desktop when I run the script from my local machine everything works
fine.

I use the following code to install the MSI & don't need to use
Get-WmiObject. Is there any way to uninstall an msi without using the
Get-WmiObject cmdlet? Any links or help would be appreciated.

$product2 = [WMICLASS]"\\MachineName.Domain.ie\ROOT\CIMV2:win32_Prod uct"
$product2.Install("D:\MyApp.msi")

I am using this code to try and uninstall & it works fine if I am logged
into the remote machine.

$product = Get-WmiObject -Class Win32_Product -Filter "name='my app'"
-ComputerName "MachineName.Domain.ie"
$product.Uninstall()
--
Thanks,
Mel
 
Unread 26-02-2008, 07:26 PM   #2
Marco Shaw [MVP]
Guest
 
Posts: n/a
Re: Get-WmiObject : Generic Failure

Mel wrote:
> Hi, I am trying to use PowerShell and WMI to uninstall a msi from a remote
> machine. I have no problem installing with WMI but cannot uninstall. I think
> it is a permissions issue but I am not sure.
>
> My issue is simple to reproduce.
>
> $strComputer = "MachineName.Domain.ie"
> $processes = Get-WmiObject -Class Win32_Process -ComputerName $strComputer
> $products = Get-WmiObject -Class Win32_Product -ComputerName $strComputer
>
> The first call with Win32_Process runs without problem. These second to
> Win32_Product does not. It returns the "Generic Failure" error message. I am
> using WinXP and trying to connect to Windows Server 2003. I am an admin on
> both machines. I have noticed that if I am logged into the server with
> Remote Desktop when I run the script from my local machine everything works
> fine.
>
> I use the following code to install the MSI & don't need to use
> Get-WmiObject. Is there any way to uninstall an msi without using the
> Get-WmiObject cmdlet? Any links or help would be appreciated.
>
> $product2 = [WMICLASS]"\\MachineName.Domain.ie\ROOT\CIMV2:win32_Prod uct"
> $product2.Install("D:\MyApp.msi")
>
> I am using this code to try and uninstall & it works fine if I am logged
> into the remote machine.
>
> $product = Get-WmiObject -Class Win32_Product -Filter "name='my app'"
> -ComputerName "MachineName.Domain.ie"
> $product.Uninstall()


Can't find it in the SDK, but maybe you need to set the PacketPrivacy in
this case. See an example here:
http://www.eggheadcafe.com/software/...6-app-poo.aspx

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
 
Unread 27-02-2008, 01:24 PM   #3
Mel
Guest
 
Posts: n/a
Re: Get-WmiObject : Generic Failure

Thanks Marco,
I took a look at the link you gave and tried it out but still get the
Generic Error message. Again if I remote desktop to my server before I run
this it works.

[wmisearcher]$wmisearcher = "SELECT * FROM Win32_Product"
$wmisearcher.scope = "\\MyServer\root\cimv2"
$wmisearcher.scope.options.EnablePrivileges = $true
$wmisearcher.scope.options.Impersonation = "Impersonate"
$wmisearcher.scope.options.Authentication = "PacketPrivacy"

$wmisearcher.Get()

I was also able to reproduce this in a C# forms application so it looks like
it is a WMI / Security issue & not directly related to PowerShell.
C# code:
ManagementScope scope = new
ManagementScope(@"\\MyServer\ROOT\CIMV2");
scope.Connect();

SelectQuery allProductsQuery = new SelectQuery("Win32_Product");
ManagementObjectSearcher allProducts = new
ManagementObjectSearcher(scope, allProductsQuery);

foreach (ManagementObject product in allProducts.Get()) //Thows
exception
{
//Do Something.
}

I eventually managed to get some code to work but it is not ideal. I need
to use the
Product Code (guid) from the MSI Project. I can then use the following
script to uninstall. I would much prefer to use the Application Name rather
than its Guid though. The code below works & the guid is the product code
from MSI Project File.

$product = New-Object
System.Management.ManagementObject("\\MyServer\roo t\cimv2:Win32_Product.IdentifyingNumber='{4ABEFB1F-005E-40BE-9ED7-A94EAE42C625}',Name='My
App',Version='1.0.0'")
$var = $product.Uninstall()

I am thinking that somebody out there must know what permissions are needed
to execute the $wmisearcher.Get() method remotely.
--
Mel


"Marco Shaw [MVP]" wrote:

> Mel wrote:
> > Hi, I am trying to use PowerShell and WMI to uninstall a msi from a remote
> > machine. I have no problem installing with WMI but cannot uninstall. I think
> > it is a permissions issue but I am not sure.
> >
> > My issue is simple to reproduce.
> >
> > $strComputer = "MachineName.Domain.ie"
> > $processes = Get-WmiObject -Class Win32_Process -ComputerName $strComputer
> > $products = Get-WmiObject -Class Win32_Product -ComputerName $strComputer
> >
> > The first call with Win32_Process runs without problem. These second to
> > Win32_Product does not. It returns the "Generic Failure" error message. I am
> > using WinXP and trying to connect to Windows Server 2003. I am an admin on
> > both machines. I have noticed that if I am logged into the server with
> > Remote Desktop when I run the script from my local machine everything works
> > fine.
> >
> > I use the following code to install the MSI & don't need to use
> > Get-WmiObject. Is there any way to uninstall an msi without using the
> > Get-WmiObject cmdlet? Any links or help would be appreciated.
> >
> > $product2 = [WMICLASS]"\\MachineName.Domain.ie\ROOT\CIMV2:win32_Prod uct"
> > $product2.Install("D:\MyApp.msi")
> >
> > I am using this code to try and uninstall & it works fine if I am logged
> > into the remote machine.
> >
> > $product = Get-WmiObject -Class Win32_Product -Filter "name='my app'"
> > -ComputerName "MachineName.Domain.ie"
> > $product.Uninstall()

>
> Can't find it in the SDK, but maybe you need to set the PacketPrivacy in
> this case. See an example here:
> http://www.eggheadcafe.com/software/...6-app-poo.aspx
>
> Marco
>
> --
> Microsoft MVP - Windows PowerShell
> http://www.microsoft.com/mvp
>
> PowerGadgets MVP
> http://www.powergadgets.com/mvp
>
> Blog:
> http://marcoshaw.blogspot.com
>

 
Unread 27-02-2008, 01:25 PM   #4
Shay Levi
Guest
 
Posts: n/a
Re: Get-WmiObject : Generic Failure


Maybe theWMIguy , Can you try this:

$server = "zion"

$co = new-object System.Management.ConnectionOptions
$co.Username="domain\username"
$co.Password="password"
$co.Authentication=[System.Management.AuthenticationLevel]:acketPrivacy
$co.EnablePrivileges=$true

$wmi = New-Object System.Management.ManagementObjectSearcher
$wmi.Query="SELECT * FROM Win32_Product"
$wmi.Scope.Path="\\$server\root\cimv2"
$wmi.Scope.Options=$co

$wmi.Get()



Can you get more info on the error, anything more then the Generic Error
message, maybe:

$error[0] | fl * -force


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com

> Thanks Marco,
> I took a look at the link you gave and tried it out but still get the
> Generic Error message. Again if I remote desktop to my server before
> I run
> this it works.
> [wmisearcher]$wmisearcher = "SELECT * FROM Win32_Product"
> $wmisearcher.scope = "\\MyServer\root\cimv2"
> $wmisearcher.scope.options.EnablePrivileges = $true
> $wmisearcher.scope.options.Impersonation = "Impersonate"
> $wmisearcher.scope.options.Authentication = "PacketPrivacy"
>
> $wmisearcher.Get()
>
> I was also able to reproduce this in a C# forms application so it
> looks like
> it is a WMI / Security issue & not directly related to PowerShell.
> C# code:
> ManagementScope scope = new
> ManagementScope(@"\\MyServer\ROOT\CIMV2");
> scope.Connect();
> SelectQuery allProductsQuery = new
> SelectQuery("Win32_Product");
> ManagementObjectSearcher allProducts = new
> ManagementObjectSearcher(scope, allProductsQuery);
> foreach (ManagementObject product in allProducts.Get())
> //Thows
> exception
> {
> //Do Something.
> }
> I eventually managed to get some code to work but it is not ideal. I
> need to use the Product Code (guid) from the MSI Project. I can then
> use the following script to uninstall. I would much prefer to use the
> Application Name rather than its Guid though. The code below works &
> the guid is the product code from MSI Project File.
>
> $product = New-Object
>
> System.Management.ManagementObject("\\MyServer\roo t\cimv2:Win32_Produc
> t.IdentifyingNumber='{4ABEFB1F-005E-40BE-9ED7-A94EAE42C625}',Name='My
>
> App',Version='1.0.0'")
>
> $var = $product.Uninstall()
>
> I am thinking that somebody out there must know what permissions are
> needed to execute the $wmisearcher.Get() method remotely.
>
> "Marco Shaw [MVP]" wrote:
>
>> Mel wrote:
>>
>>> Hi, I am trying to use PowerShell and WMI to uninstall a msi from a
>>> remote machine. I have no problem installing with WMI but cannot
>>> uninstall. I think it is a permissions issue but I am not sure.
>>>
>>> My issue is simple to reproduce.
>>>
>>> $strComputer = "MachineName.Domain.ie"
>>> $processes = Get-WmiObject -Class Win32_Process -ComputerName
>>> $strComputer
>>> $products = Get-WmiObject -Class Win32_Product -ComputerName
>>> $strComputer
>>> The first call with Win32_Process runs without problem. These
>>> second to Win32_Product does not. It returns the "Generic Failure"
>>> error message. I am using WinXP and trying to connect to Windows
>>> Server 2003. I am an admin on both machines. I have noticed that
>>> if I am logged into the server with Remote Desktop when I run the
>>> script from my local machine everything works fine.
>>>
>>> I use the following code to install the MSI & don't need to use
>>> Get-WmiObject. Is there any way to uninstall an msi without using
>>> the Get-WmiObject cmdlet? Any links or help would be appreciated.
>>>
>>> $product2 =
>>> [WMICLASS]"\\MachineName.Domain.ie\ROOT\CIMV2:win32_Prod uct"
>>> $product2.Install("D:\MyApp.msi")
>>>
>>> I am using this code to try and uninstall & it works fine if I am
>>> logged into the remote machine.
>>>
>>> $product = Get-WmiObject -Class Win32_Product -Filter "name='my
>>> app'" -ComputerName "MachineName.Domain.ie" $product.Uninstall()
>>>

>> Can't find it in the SDK, but maybe you need to set the PacketPrivacy
>> in this case. See an example here:
>> http://www.eggheadcafe.com/software/...merating-iis-6
>> -app-poo.aspx
>>
>> Marco
>>
>> --
>> Microsoft MVP - Windows PowerShell
>> http://www.microsoft.com/mvp
>> PowerGadgets MVP
>> http://www.powergadgets.com/mvp
>> Blog:
>> http://marcoshaw.blogspot.com



 
Unread 27-02-2008, 01:25 PM   #5
Marco Shaw [MVP]
Guest
 
Posts: n/a
Re: Get-WmiObject : Generic Failure


> Can't find it in the SDK, but maybe you need to set the PacketPrivacy in
> this case. See an example here:
> http://www.eggheadcafe.com/software/...6-app-poo.aspx


And it if turns out to be this... The method to change the
PacketPrivacy is *much* easier in v2...

Marco
 
Unread 27-02-2008, 02:20 PM   #6
Mel
Guest
 
Posts: n/a
Re: Get-WmiObject : Generic Failure

I tried the code you gave but got the same error. Here is the full error
message.

ErrorRecord : An error occurred while enumerating through a collection:
Generic failure .
StackTrace : at
System.Management.Automation.ParserOps.MoveNext(Ex ecutionContext context,
Token token, IEnumerator enumerato
r)
at
System.Management.Automation.ParseTreeNode.appendR esult(ExecutionContext
context, Object result, Pipe output
Pipe, ArrayList& resultList)
at
System.Management.Automation.ParseTreeNode.Execute (Array input, Pipe
outputPipe, ArrayList& resultList)
at
System.Management.Automation.Parser.StatementListN ode.Execute(Array input,
Pipe outputPipe, ArrayList& resul
tList)
Message : An error occurred while enumerating through a collection:
Generic failure .
Data : {}
InnerException : System.Management.ManagementException: Generic failure
at
System.Management.ManagementException.ThrowWithExt endedInfo(ManagementStatus
errorCode)
at
System.Management.ManagementObjectCollection.Manag ementObjectEnumerator.MoveNext()
at
System.Management.Automation.ParserOps.MoveNext(Ex ecutionContext context,
Token token, IEnumerator enumerato
r)
TargetSite : System.Array Synchronou***ecuteEnumerate(System.Object,
System.Collections.Hashtable, Boolean)
HelpLink :
Source : System.Management.Automation
--
Mel


"Shay Levi" wrote:

>
> Maybe theWMIguy , Can you try this:
>
> $server = "zion"
>
> $co = new-object System.Management.ConnectionOptions
> $co.Username="domain\username"
> $co.Password="password"
> $co.Authentication=[System.Management.AuthenticationLevel]:acketPrivacy
> $co.EnablePrivileges=$true
>
> $wmi = New-Object System.Management.ManagementObjectSearcher
> $wmi.Query="SELECT * FROM Win32_Product"
> $wmi.Scope.Path="\\$server\root\cimv2"
> $wmi.Scope.Options=$co
>
> $wmi.Get()
>
>
>
> Can you get more info on the error, anything more then the Generic Error
> message, maybe:
>
> $error[0] | fl * -force
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
> > Thanks Marco,
> > I took a look at the link you gave and tried it out but still get the
> > Generic Error message. Again if I remote desktop to my server before
> > I run
> > this it works.
> > [wmisearcher]$wmisearcher = "SELECT * FROM Win32_Product"
> > $wmisearcher.scope = "\\MyServer\root\cimv2"
> > $wmisearcher.scope.options.EnablePrivileges = $true
> > $wmisearcher.scope.options.Impersonation = "Impersonate"
> > $wmisearcher.scope.options.Authentication = "PacketPrivacy"
> >
> > $wmisearcher.Get()
> >
> > I was also able to reproduce this in a C# forms application so it
> > looks like
> > it is a WMI / Security issue & not directly related to PowerShell.
> > C# code:
> > ManagementScope scope = new
> > ManagementScope(@"\\MyServer\ROOT\CIMV2");
> > scope.Connect();
> > SelectQuery allProductsQuery = new
> > SelectQuery("Win32_Product");
> > ManagementObjectSearcher allProducts = new
> > ManagementObjectSearcher(scope, allProductsQuery);
> > foreach (ManagementObject product in allProducts.Get())
> > //Thows
> > exception
> > {
> > //Do Something.
> > }
> > I eventually managed to get some code to work but it is not ideal. I
> > need to use the Product Code (guid) from the MSI Project. I can then
> > use the following script to uninstall. I would much prefer to use the
> > Application Name rather than its Guid though. The code below works &
> > the guid is the product code from MSI Project File.
> >
> > $product = New-Object
> >
> > System.Management.ManagementObject("\\MyServer\roo t\cimv2:Win32_Produc
> > t.IdentifyingNumber='{4ABEFB1F-005E-40BE-9ED7-A94EAE42C625}',Name='My
> >
> > App',Version='1.0.0'")
> >
> > $var = $product.Uninstall()
> >
> > I am thinking that somebody out there must know what permissions are
> > needed to execute the $wmisearcher.Get() method remotely.
> >
> > "Marco Shaw [MVP]" wrote:
> >
> >> Mel wrote:
> >>
> >>> Hi, I am trying to use PowerShell and WMI to uninstall a msi from a
> >>> remote machine. I have no problem installing with WMI but cannot
> >>> uninstall. I think it is a permissions issue but I am not sure.
> >>>
> >>> My issue is simple to reproduce.
> >>>
> >>> $strComputer = "MachineName.Domain.ie"
> >>> $processes = Get-WmiObject -Class Win32_Process -ComputerName
> >>> $strComputer
> >>> $products = Get-WmiObject -Class Win32_Product -ComputerName
> >>> $strComputer
> >>> The first call with Win32_Process runs without problem. These
> >>> second to Win32_Product does not. It returns the "Generic Failure"
> >>> error message. I am using WinXP and trying to connect to Windows
> >>> Server 2003. I am an admin on both machines. I have noticed that
> >>> if I am logged into the server with Remote Desktop when I run the
> >>> script from my local machine everything works fine.
> >>>
> >>> I use the following code to install the MSI & don't need to use
> >>> Get-WmiObject. Is there any way to uninstall an msi without using
> >>> the Get-WmiObject cmdlet? Any links or help would be appreciated.
> >>>
> >>> $product2 =
> >>> [WMICLASS]"\\MachineName.Domain.ie\ROOT\CIMV2:win32_Prod uct"
> >>> $product2.Install("D:\MyApp.msi")
> >>>
> >>> I am using this code to try and uninstall & it works fine if I am
> >>> logged into the remote machine.
> >>>
> >>> $product = Get-WmiObject -Class Win32_Product -Filter "name='my
> >>> app'" -ComputerName "MachineName.Domain.ie" $product.Uninstall()
> >>>
> >> Can't find it in the SDK, but maybe you need to set the PacketPrivacy
> >> in this case. See an example here:
> >> http://www.eggheadcafe.com/software/...merating-iis-6
> >> -app-poo.aspx
> >>
> >> Marco
> >>
> >> --
> >> Microsoft MVP - Windows PowerShell
> >> http://www.microsoft.com/mvp
> >> PowerGadgets MVP
> >> http://www.powergadgets.com/mvp
> >> Blog:
> >> http://marcoshaw.blogspot.com

>
>
>

 
 

Thread Tools
Display Modes



< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT. The time now is 10:18 PM.


vBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2013, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional