Link to home
Start Free TrialLog in
Avatar of bibi92
bibi92Flag for France

asked on

how can I test get-wmiobject

Hello,

How can I modify this code for testing a wmi query without having the following error :
Get-WmiObject : Invalid namespace
At line:3 char:23
+ $cluster=get-wmiobject <<<<  -class "MSCluster_Cluster" -namespace "root\mscluster" -computername "$mach_name" | select -ExpandProperty Name
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

The query :
try
{
$cluster=get-wmiobject -class "MSCluster_Cluster" -namespace "root\mscluster" -computername "$mach_name" | select -ExpandProperty Name    
}
catch [Exception]
{ 
    echo "$cluster" | out-file $LOG_FILE -ErrorVariable ERR1 -encoding "default" -append -ErrorAction silentlycontinue 
}

Open in new window

Thanks
bibi
Avatar of Neil Russell
Neil Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

The namespace should be....

-namespace "root\cluster"
P.S.

If this is in a windows server 2008 R2 environment, use directly the Powershell cluster cmdletts

http://blogs.msdn.com/b/clustering/archive/2009/05/21/9633316.aspx
Avatar of bibi92

ASKER

This script can be execute on windows server 2008 R2 or 2003.
Same error with -namespace "root\cluster" .

Thanks

Regards
bibi
On a server that is part of a cluster can you run the following in powershell?

get-wmiobject -class "MSCluster_Cluster" -namespace "root\cluster"
Avatar of bibi92

ASKER

Already done, I want to test if the server is a clustered or not. If I execute the script and the server is not a cluster, the error occurs :
Get-WmiObject : Invalid namespace
At line:3 char:23
+ $cluster=get-wmiobject <<<<  -class "MSCluster_Cluster" -namespace "root\mscluster" -computername "$mach_name" | select -ExpandProperty Name

Thanks
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bibi92

ASKER

Thanks regards bibi