Archive for June, 2015

get disk queue length – powershell

June 4, 2015

DECLARE @b TABLE (output VARCHAR(MAX))
INSERT INTO @b
EXEC xp_cmdshell ‘C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command “(get-counter ”\PhysicalDisk(1 d:)\Current Disk Queue Length” -ComputerName COMPUTERNAME).countersamples | select CookedValue”‘
;WITH a AS (SELECT *,ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) r FROM @b)
SELECT LTRIM(output)
FROM a WHERE r = 4

querying an xml column

June 2, 2015

simple example

SELECT CAST(

james
lester

‘ AS XML) xml_column
INTO #data_table

SELECT n.l.value(‘first_name[1]’,’VARCHAR(100)’) AS destination_record_count
FROM #data_table a
CROSS APPLY xml_column.nodes(‘//staff’) n(l)