开发者

Access SQL - WMI Namespaces from Remote Machine

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\SqlSer开发者_如何学JAVAver" >> 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!


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜