Question

i am playing with Powershell and SQL WMI events and i am wondering if i can do this stuff remotely from the admin notebook:

I'd like to query the "root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER" namespace:

On SQLServer directly:

get-wmiobject -list -namespace "root\Microsoft\SqlServer" >> Works!

get-wmiobject -list -namespace "root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER" >> Works !

On my Adminmachine:

get-wmiobject -list -namespace "root\Microsoft\SqlServer" >> Works!

get-wmiobject -list -namespace "root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER" >> Error: Invalid Namespace.

Is there a trick to get this running? Do i have to additional install sth? I am still on SQL 2005.

Thanks!

Was it helpful?

Solution

Use the computername name parameter.

get-wmiobject -computername Z002 -list -namespace "root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER"

Also keep in mind MSSQLSERVER is only available if the server has a default instance. If the server uses a named instance you'll need to specify the instance name instead of MSSQLSERVER.

OTHER TIPS

Posted - 05/05/2012 : 08:25:20

Hi All,

We've developed a free WMI CLR assembly to execute WMI queries in SQL.

e.g. This will return mount point and drive space

DECLARE @XmlData Xml
--Obtain Windows Services 
select @XmlData=dbo.GetWMI('\\SQL2008WIN2008\root\cimv2', --Machine and WMI class
NULL, --UserName, leave NULL to use current
NULL, --Password, leave NULL to use current 
'select * from win32_volume' --WMI Class
)

SELECT 
tbl.A.value('(DeviceID)[1]','VARCHAR(100)') as DeviceID,
tbl.A.value('(Name)[1]','VARCHAR(200)') as Name,
tbl.A.value('(DriveType)[1]','int') as DriveType,
ISNULL(tbl.A.value('(DriveLetter)[1]','VARCHAR(10)'),'MountPoint') as DriveLetter,
tbl.A.value('(FreeSpace)[1]','bigint')/1024/1024 as FreeSpaceMbytes
FROM @XmlData.nodes('/WMI/Data') tbl(A)

Have a look at http://micatio.com/sqlwmi.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top