Avatar of bibi92
bibi92
Flag 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
Powershell

Avatar of undefined
Last Comment
bibi92

8/22/2022 - Mon
Neil Russell

The namespace should be....

-namespace "root\cluster"
Neil Russell

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
bibi92

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

Thanks

Regards
bibi
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Neil Russell

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

get-wmiobject -class "MSCluster_Cluster" -namespace "root\cluster"
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
SubSun

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
bibi92

ASKER
Thanks regards bibi
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.