none
How to automate deployment of Script to a collection RRS feed

  • Question

  • Hi All,

    As we know, with SCCM CB 1706 and above, we can create and run/deploy powershell script directly to a host client or an collection from the SCCM configuration manager console directly as documented here:

    https://docs.microsoft.com/en-us/sccm/apps/deploy-use/create-deploy-scripts

    Just wanted to know, is there a way we can automate targeting an existing script to collection or host machines, I mean the steps involved to run script in the link mentioned above. From the documentation, this seems to be an manual process.

    Kindly advice.


    • Edited by DS2885 Thursday, April 4, 2019 5:00 PM
    Thursday, April 4, 2019 4:54 PM

Answers

All replies

    • Edited by KevinMJohnston Thursday, April 4, 2019 6:27 PM
    • Proposed as answer by Jason SandysMVP Thursday, April 4, 2019 10:01 PM
    • Marked as answer by DS2885 Friday, April 5, 2019 11:47 AM
    • Unmarked as answer by DS2885 Friday, April 5, 2019 8:11 PM
    • Marked as answer by DS2885 Saturday, April 6, 2019 3:15 PM
    Thursday, April 4, 2019 6:25 PM
  • Helli DS2885,
     
    Does the script exist in the SCCM or not? If yes, we could Get-CMScript, Invoke-CMScript, Approve-CMScript, Deny-CMScript or Remove-CMScript as KevinMJohnston mentioned above.
     
    However, New-CMScript is not available currently. That means we have to create a script manually in SCCM for now.
     
    Hope my answer could help you and look forward to your feedback.
     
    Best Regards,
    Ray

    Please remembers to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Marked as answer by DS2885 Friday, April 5, 2019 11:47 AM
    • Unmarked as answer by DS2885 Friday, April 5, 2019 8:11 PM
    Friday, April 5, 2019 2:08 AM
  • Thank You Kevin and Ray for your suggestion of commandlet approach..

    The only challenge is see with this approach is the need to install configuration manager console on the machine to leverage the benefit of these SDK and I cannot have all the desktop support team members install configuration Manager console on their machines..

    So was wondering if it is possible to trigger deployment of pre-created script on host machines via WMI..

    The WMI class for this I believe would be SMS_Scripts but not could not figure out a way how to leverage the same to trigger script deployment from a remote machine using PS script.

    Some documentation I found on net using WMI to create and approve script is listed in below link

    https://www.scconfigmgr.com/2017/08/22/automate-scripts-in-configmgr-using-powershell/

    Thank You once again for your suggestion!



    Friday, April 5, 2019 11:46 AM
  • Hi,

    I am trying to execute the following script but get error: ' Type mismatch for parameter "Type" '

    Am running this script from a remote machine and the account is an SCCM Admin account.

    # Site information
    $SiteServer = "[SiteServer]"
    $SiteCode = "[SiteCode]"

    # Input parameters for method execution
    $ScriptArgs = @{
        TargetCollectionID = "[CollectionID]"
        Type = "135"
    }
    # Invoke Script
    Invoke-CimMethod -Namespace "\\$($SiteServer)\root\SMS\site_$($SiteCode)" -ClassName SMS_ClientOperation -MethodName InitiateClientOperationEx -Arguments $ScriptArgs

    Can anyone suggest what am I missing here?

    Thank You!



    • Edited by DS2885 Wednesday, April 17, 2019 1:21 PM
    Wednesday, April 17, 2019 1:00 PM
  • The Type parameter for that method is an integer by your hash table above has it as a string.

    Jason | https://home.configmgrftw.com | @jasonsandys

    Wednesday, April 17, 2019 2:23 PM
  • Tried below but I still get the error:  Type mismatch for parameter "Type" 

    $SiteServer = "[SiteServer]"
    $SiteCode = "[SiteCode]"
    [int]$Type = '135'
    # Input parameters for method execution
    $ScriptArgs = @{
        TargetCollectionID = "[CollectionID]"
        Type = $Type
    }
    # Invoke Script
    Invoke-CimMethod -Namespace "\\$($SiteServer)\root\SMS\site_$($SiteCode)" -ClassName SMS_ClientOperation -MethodName InitiateClientOperationEx -Arguments $ScriptArgs

    Saturday, September 28, 2019 5:12 AM