{"id":195,"date":"2023-06-01T23:20:35","date_gmt":"2023-06-02T03:20:35","guid":{"rendered":"https:\/\/ziviz.us\/WP\/?p=195"},"modified":"2023-06-01T23:22:36","modified_gmt":"2023-06-02T03:22:36","slug":"create-sccm-script-detection-in-powershell","status":"publish","type":"post","link":"https:\/\/www.ziviz.net\/WP\/2023\/06\/01\/create-sccm-script-detection-in-powershell\/","title":{"rendered":"Create SCCM Script Detection in PowerShell"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This is mostly a post about me being dumb.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you create an application in PowerShell for SCCM, you usually create detection methods with <code>New-CMDetectionClause*<\/code> cmdlets like <code>New-CMDetectionClauseFile<\/code>. So I was expecting there to be a matching <code>New-CMDetectionClauseScript<\/code> or something like that. But that does not exist. Googling this hardly helped as I kept getting results on how to use PowerShell detection methods, not how to create them from within PowerShell. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Turns out, the script detection method is baked into the <code>Add-CM*Deployment<\/code> methods. Such as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$DetectionScript = @\"\nif ($SomeCondition -eq $true) {\n\tWrite-Host \"Installed\"\n}\nexit 0\n\"@\n\nAdd-CMScriptDeploymentType -DeploymentTypeName \"SomeDT\" -InstallCommand \"Setup.bat\" -ApplicationName \"MyApp\" -ScriptText $DetectionScript -ScriptLanguage PowerShell -ContentLocation \"\\\\SomeServer\\SomeShare\\PackageSource\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It&#8217;s in the documentation&#8230; I just never considered it could be part of the DeploymentType function and not it&#8217;s own DetectionClause function like the other types. It makes sense, don&#8217;t get me wrong&#8230; It lines up with the form in the admin console when manually creating the script-based detection method. I just did not think of it&#8230;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since I am making a post on this, definitely check out the documentation on how SCCM uses the detection script output: <a rel=\"noreferrer noopener\" href=\"https:\/\/learn.microsoft.com\/en-us\/previous-versions\/system-center\/system-center-2012-R2\/gg682159(v=technet.10)#to-use-a-custom-script-to-determine-the-presence-of-a-deployment-type\" data-type=\"URL\" data-id=\"https:\/\/learn.microsoft.com\/en-us\/previous-versions\/system-center\/system-center-2012-R2\/gg682159(v=technet.10)#to-use-a-custom-script-to-determine-the-presence-of-a-deployment-type\" target=\"_blank\">https:\/\/learn.microsoft.com\/en-us\/previous-versions\/system-center\/system-center-2012-R2\/gg682159(v=technet.10)#to-use-a-custom-script-to-determine-the-presence-of-a-deployment-type<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is mostly a post about me being dumb. When you create an application in PowerShell for SCCM, you usually create detection methods with New-CMDetectionClause* cmdlets like New-CMDetectionClauseFile. So I was expecting there to be a matching New-CMDetectionClauseScript or something like that. But that does not exist. Googling this hardly helped as I kept getting &hellip; <a href=\"https:\/\/www.ziviz.net\/WP\/2023\/06\/01\/create-sccm-script-detection-in-powershell\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Create SCCM Script Detection in PowerShell&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,8,7],"tags":[],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-powershell","category-sccm","category-sysadmin"],"_links":{"self":[{"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/comments?post=195"}],"version-history":[{"count":1,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":196,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/posts\/195\/revisions\/196"}],"wp:attachment":[{"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/media?parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/categories?post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/tags?post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}