{"id":18494564,"url":"https://github.com/madeiradata/clrwmirequest","last_synced_at":"2026-04-24T23:33:34.355Z","repository":{"id":72814850,"uuid":"156733340","full_name":"MadeiraData/ClrWmiRequest","owner":"MadeiraData","description":"SQL Server CLR function that uses System.Management to run WMI queries and return results as XML","archived":false,"fork":false,"pushed_at":"2019-04-21T11:29:27.000Z","size":16,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-11T12:12:20.078Z","etag":null,"topics":["sqlclr","sqlserver","wmi","xml"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MadeiraData.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-11-08T16:07:16.000Z","updated_at":"2023-11-14T08:08:40.000Z","dependencies_parsed_at":"2023-02-26T17:30:43.759Z","dependency_job_id":null,"html_url":"https://github.com/MadeiraData/ClrWmiRequest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MadeiraData/ClrWmiRequest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MadeiraData%2FClrWmiRequest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MadeiraData%2FClrWmiRequest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MadeiraData%2FClrWmiRequest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MadeiraData%2FClrWmiRequest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MadeiraData","download_url":"https://codeload.github.com/MadeiraData/ClrWmiRequest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MadeiraData%2FClrWmiRequest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32245148,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sqlclr","sqlserver","wmi","xml"],"created_at":"2024-11-06T13:20:33.788Z","updated_at":"2026-04-24T23:33:34.340Z","avatar_url":"https://github.com/MadeiraData.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ClrWmiRequest\n\nSQL Server CLR function that uses System.Management to run WMI queries and return results as XML.\n\n# Example Use Cases\n\nQuery processor information for current machine:\n\n```\nDECLARE @server NVARCHAR(255) = '.'\nDECLARE @query NVARCHAR(MAX) = 'SELECT * FROM Win32_Processor'\nDECLARE @headers NVARCHAR(MAX)\n\nDECLARE @results XML\n\nSET @results = dbo.clr_wmi_request(@server, @query, @headers)\n\nSELECT\n\tX.value('(@Name)[1]', 'nvarchar(max)'),\n\tX.value('(./Path/text())[1]', 'nvarchar(max)'),\n\tX.query('./Properties')\nFROM @results.nodes('Response/Result/Item') AS T(X)\n\n```\n\n# The CLR Function\nThis is a SQL Server CLR function that calls an assembly written in C#, utilizing its ManagementScope class to run a WMI query and return the response.\n\n## Input Parameters\nThese are the parameters that can be passed into the function:\n\n### server (string)\nUse \".\" to query from the current machine (i.e. the one where the SQL Server instance is installed).\nYou can also use this parameter to specify a remote server, but in order for it to work, you must make sure\nthat the SQL Server instance has permissions to perform remote WMI queries.\nUse the steps in this guide to set it up: https://www.netwrix.com/kb/1630\n\n### query (string)\nThis is the WMI query that you want to run against the specified server.\nFor example: \"SELECT * FROM Win32_Processor\"\n\n### headers (string, in XML format)\nThis allows you to set headers for the WMI query. They are passed as XML following this format:\n```\n\t\u003cHeaders\u003e\n\t\t\t\u003cHeader Name=\"MyHeader\"\u003eMy Header's Value\u003c/Header\u003e\n\t\t\t\u003cHeader Name=\"…\"\u003e…\u003c/Header\u003e\n\t\t\t\u003cHeader Name=\"…\"\u003e…\u003c/Header\u003e\n\t\u003c/Headers\u003e\n```\nYou can use these headers to specify options for the ManagementScope object.\nThe various supported headers are:\n\n* **Authentication** (string) - Must be a string value from the *AuthenticationLevel* enum:\n  * Unchanged\n  * Default\n  * None\n  * Connect\n  * Call\n  * Packet\n  * PacketIntegrity\n  * PacketPrivacy\n* **QueryLanguage** (string) - Sets the query language to be used (default: WQL).\n* **Impersonation** (string) - Must be a string value from the *ImpersonationLevel* enum:\n  * Default\n  * Anonymous\n  * Identify\n  * Impersonate\n  * Delegate\n* **EnablePriviliges** (boolean) - Sets whether user privileges need to be enabled for the connection operation.\n* **Username** (string) - Sets the user name to be used for the connection operation.\n* **Password** (string) - Sets the password for the specified user.\n* **Authority** (string) - Sets the authority used to authenticate the specified user.\n* **SecurePassword** (string) - Sets the password for the specified user, created as a SecureString object.\n* **Timeout** (int) - Sets the timeout, in milliseconds, for the WMI operation.\n\n\n## Results\n\nThe result from this function is an XML document generated from the ManagementScope and ManagementObjectSearcher class objects, and the results of the WMI query formatted in XML.\n\n* Response - this is the root element\n  * Headers - each header will get its own node here\n    * Name\n    * Value\n    * In addition to the configuration headers, you'd also get 2 new headers \"Success\" (boolean = True) and \"Count\" (number).\n  * Result - this will contain the content from the response\n    * Item - each \"Item\" element represents a single row returned from the WMI query\n      * Name - each Item element has the \"Name\" attribute\n      * Path - each Item element has its full \"Path\" as a sub-element\n      * Properties - this will contain the collection of properties of each item (i.e. the \"fields\" from the query)\n        * Property - this contains a single property of a given item\n\t    * Name - each property element has a single \"Name\" attribute\n\t    * Value - the contents of the Property element is its value\n\t    \nIn case of an error, the results would look a bit different:\n\n* Response - this is the root element\n  * Headers - each header will get its own node here\n    * Name\n    * Value\n    * In addition to the configuration headers, you'd also get 2 new headers \"Success\" (boolean = False) and \"Count\" (number = 0).\n  * Result - this will contain the content from the response\n    * Error - one Error element will return with info about the error:\n      * Source - the \"Source\" attribute will contain the source of the error\n      * Message - the \"Message\" sub-element will contain the error message\n      * StackTrace - the \"StackTrace\" sub-element will contain... you guessed it - the stack trace\n\t    \n### Example Results\n\n```\n\u003cResponse\u003e\n  \u003cHeaders\u003e\n      \u003cHeader Name=\"Success\"\u003eTrue\u003c/Header\u003e\n      \u003cHeader Name=\"...\"\u003e...\u003c/Header\u003e\n      \u003cHeader Name=\"Count\"\u003e2\u003c/Header\u003e\n  \u003c/Headers\u003e\n  \u003cResult\u003e\n      \u003cItem Name=\"MyService\"\u003e\n          \u003cPath\u003eMyComputer\\root\\cimv2\\Win32_Service[\"MyService\"]\u003c/Path\u003e\n          \u003cProperties\u003e\n              \u003cProperty Name=\"State\"\u003eStarted\u003c/Property\u003e\n              \u003cProperty Name=\"...\"\u003e...\u003c/Property\u003e\n              \u003cProperty Name=\"...\"\u003e...\u003c/Property\u003e\n          \u003c/Properties\u003e\n      \u003c/Item\u003e\n      \u003cItem Name=\"...\"\u003e\n          \u003cPath\u003e...\u003c/Path\u003e\n          \u003cProperties\u003e\n              \u003cProperty Name=\"...\"\u003e...\u003c/Property\u003e\n              \u003cProperty Name=\"...\"\u003e...\u003c/Property\u003e\n              \u003cProperty Name=\"...\"\u003e...\u003c/Property\u003e\n          \u003c/Properties\u003e\n      \u003c/Item\u003e\n```\n\n### Example Results with Errors\n\n```\n\u003cResponse\u003e\n  \u003cHeaders\u003e\n      \u003cHeader Name=\"Success\"\u003eFalse\u003c/Header\u003e\n      \u003cHeader Name=\"...\"\u003e...\u003c/Header\u003e\n      \u003cHeader Name=\"Count\"\u003e0\u003c/Header\u003e\n  \u003c/Headers\u003e\n  \u003cResult\u003e\n      \u003cError Source=\"...\"\u003e\n         \u003cMessage\u003e...\u003c/Message\u003e\n         \u003cStackTrace\u003e...\u003c/StackTrace\u003e\n      \u003c/Error\u003e\n  \u003c/Result\u003e\n\u003c/Response\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadeiradata%2Fclrwmirequest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmadeiradata%2Fclrwmirequest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadeiradata%2Fclrwmirequest/lists"}