Invoke OSD Task sequence remotely with Powershell

 

Earlier blog posts on invoking Installations:

Applications 

Software Updates

 

This is a continuation on how to invoke or trigger installations in Software center remotely with the help of Powershell. This blog post came about after i got a question from a user called Sonik on the Application post i did.

 

Question:

Will this work to install Operating System as well? I have the operating system image available in the software center and It works when I manually select and install. But not with this script. Any idea?

 

Answer:

Hey, No it won’t work because Configuration Manager uses different built in functions to trigger OSD then applications. I don’t know which WMI class it is right now but i will take a look and see if i can figure it out.

 

And below is the result on how to do it. Hope this will help you Sonik.

 

What do we want to Achieve?

 

We wan’t to be able to invoke an installation of an available OSD Task Sequence in Software Center remotely on a system.

One might wonder why and it’s pretty simple, it saves us time and we are lazy 😀

1

 

The Script

 


function Invoke-OSDInstall
{
Param
(
[String][Parameter(Mandatory=$True, Position=1)] $Computername,
[String][Parameter(Mandatory=$True, Position=2)] $OSDName

)
Begin
{

$CIMClass = (Get-CimClass -Namespace root\ccm\clientsdk -ComputerName $Computername -ClassName CCM_ProgramsManager)
$OSD = (Get-CimInstance -ClassName CCM_Program -Namespace "root\ccm\clientSDK" -ComputerName $Computername | Where-Object {$_.Name -like "$OSDName"})

$Args = @{PackageID = $OSD.PackageID
ProgramID = $OSD.ProgramID
}
}

Process
{

Invoke-CimMethod -CimClass $CIMClass -ComputerName $Computername -MethodName "ExecuteProgram" –Arguments $Args

}
End {}
}

 

The script is also available for download over at Technet https://gallery.technet.microsoft.com/Invoke-Installation-of-OSD-ff6f2eb0

 

Example

 

Until next time, cheers Timmy !

You can find me over at

[twitter-follow screen_name=’Timmyitdotcom’]

14 comments

  1. Unfortunately it does not work for me. Has been tested remotely and locally on the client. Receiving an error on Invoke CimMethod:

    Invoke-CimMethod : There is no instance of the specified property values.
    At line:54 char:1
    + Invoke-CimMethod -CimClass $CIMClass -ComputerName $Computername -MethodName "Ex ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (root/ccm/clientsdk:CCM_ProgramsManager:String) [Invoke-CimMethod], CimException
        + FullyQualifiedErrorId : HRESULT 0x8033801a,Microsoft.Management.Infrastructure.CimCmdlets.InvokeCimMethodCommand
        + PSComputerName        : vm-6E9BAB

    If I’m on the client connects me to the “rootccmclientSDK” via Wbemtest or WMI Explorer and run “SELECT * FROM CCM_Program” I get no results at all. I might do something wrong but it looks strange.

    Would appreciate some help troubleshoot this.

    1. You can just ignore that error msg as for now, i get the same one as you can see in the video but that doesn’t stop the Script from working.

      If you get no result when running “SELECT * FROM CCM_Program” then i think its because there’s no deployment to that specific client, double check in Software center on the local client that the Task Sequence appears. If its visable, run the script again and check the Execmgr.log file in C:\windows\ccm\logs

      Let me know how it goes,

      1. Thanks for the quick reply!

        I do have two OS Deployments available in Software center on the client computer. Nothing new in execmgr.log. The function is returning empty values from ProgramID & PackageID.

      2. If there’s nothing in CCM_Program then there’s nothing to retun so thats why ProgramID and PackageID is empty.

        Here’s how it looks on my Client http://imgur.com/a/bX5KW

        Hard to say exactly what it could be without seeing it for my self. But make sure that the deployments are correct and works when you do it manually
        you can also try to run ccmrepair.exe just in case and/or try it on another client.

      3. Well, it’s strange! I did check with wmemtest and powershell an there is nothing there if I check localy on the clients but everything with application and OS-deployment works great via Software Center.

        If I try to run this PS command against a remote computer I get this error:

        get-ciminstance -ClassName CCM_Program -Namespace "rootccmclientSDK" -ComputerName testcomputer01
        get-ciminstance : Tjänsten WS Management kan inte behandla begäran. En URI för en DMTF-resurs användes för att komma åt en klass som inte är DMTF. Försök igen med en URI som inte är en DMTF-resurs.
        At line:1 char:1
        + get-ciminstance -ClassName CCM_Program -Namespace "rootccmclientSDK" -Computer ...
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            + CategoryInfo          : NotSpecified: (rootccmclientSDK:CCM_Program:String) [Get-CimInstance], CimException
            + FullyQualifiedErrorId : HRESULT 0x80338139,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
            + PSComputerName        : testcomputer01

        Get the same error in ISE if I run your Remote Software Center ant the message in the tool is “Cannot validate argument on parameter “Items”. The argument is null. Supply a non-null argument and try again.”.

        It’s realy strange that can’t find anything in CCM_Program but everything works.

  2. So I know now that CCM_Program isn’t empty! The thing is that if I run the Get-CimInstance command from an elevated prompt, ISE or Wbemtest the it’s empty byt if I don’t elevate then I do get all the values. Strange but tru. But I still cant use the script or tool do to the issues above.

    1. hmm that is strange for sure. what Powershell version are you running on the client?
      just run the cmdlet Get-host locally on the client and you get the version.

      As for the Remote software center problem “Cannot validate argument on parameter “Items”.
      There’s been a few people reporting that but i havent been able to reproduce it.

      There’s a discussion in this thread: https://www.reddit.com/r/SCCM/comments/5oa3xh/remote_software_center_concept_preview/

  3. I ran this command with no luck on a PC that no user was logged into, however after I logged into the computer under my credentials then triggered the powershell remotely it worked. Odd I had to be logged in to the PC running the install. Does this seem normal? Thanks for the support!

  4. Hi Tim,

    I have tried your script and nothing runs.
    Tried differnt task sequenc same problem .

    Script runs with There is no instance of the specified property values error and that’s all.

    please advise

  5. one issue I notice is when I run below line of script when $OSDName replaced with my task sequence name , No value returns

    $OSD = (Get-CimInstance -ClassName CCM_Program -Namespace “rootccmclientSDK” -ComputerName $Computername | Where-Object {$_.Name -like “$OSDName”})

    Test

    $OSD = (Get-CimInstance -ClassName CCM_Program -Namespace “rootccmclientSDK” -ComputerName $Computername | Where-Object {$_.Name -like “ABCTS”})

Leave a Reply