A really useful powershell snippet when creating deployments and testing application packages….
I was creating a Windows 7 image and wanted to add applications to the build task sequence, a base application set for the image, and once I had the packages created in SCCM I was using Advertised Programs to test the installations on a newly built image. To do this I was using a VMWare machine, so I was running the console for the client and in my impatience cycling the policy updates manually to see if the apps would deploy ok. Anyway I got annoyed with VMWare console mouse-handling on this machine and decided it would be much better to advertise the program then refresh the policy on the client with a powershell script.
A good friend of mine, we’ll call her Emma because that’s her name, wrote a neat little utility to invoke the TriggerSchedule methods on SCCM Clients, so I borrowed from that:
$tb_Client = “ClientPC”
$SMSCli = [wmiclass] “\\$tb_Client\root\ccm:SMS_Client”
# Machine Policy Retrieval & Evaluation
$SMSCli.TriggerSchedule(“{00000000-0000-0000-0000-000000000021}”)
This works nicely on domain machines but my client was not yet domain-joined so I needed to pass credentials. Unfortunately the [wmi] and [wmiclass] type accelerators don’t allow you to pass credentials.
GWMI? That returns an instance but does not allow access to the static methods associated with the class.
Fortunately another good friend, Marc, was on hand to point me in the right direction.
“You need the class not the instance (as the class has the static methods you need)
But you need to do that remotely and the [WMICLASS] accelerator does not give you the option to authenticate with different credentials.
Solution is here to make the connection yourself, as that is more flexible as using the accelerator, using a management scope
In your case this would look like this :
$server = ‘Server’
$ms = new-object system.management.managementscope
$ms.path = “\\$server\root\CCM”
$options = $ms.Options
$Options.Username = ‘domain\user’
$Options.Password = ‘Password’
$ms.Options = $options
$mc = New-Object System.Management.ManagementClass($ms , ‘sms_client’,$null)
$mc
”
The next line, to generate a computer policy cycle is:
$mc.invokeMethod(‘TriggerSchedule’,'{00000000-0000-0000-0000-000000000021}’)
Fantastic, we all get by with help from our friends.
Thanks to Emma Harlow and Marc van Orsouw for this blog post.
Please check out http://thepowershellguy.com/blogs/posh/
The Branch Distribution Point Maintenance Task does not get triggered by sending the corresponding TriggerSchedule number (…61). You can, however, do it another way as shown in this WMIC command line:
WMIC /node:”computername” /namespace:\\root\ccm path sms_client call PDPMaintenanceTask
Is there a way to do this with PowerShell?
Does calling the method directly from the Class Object work?
$mc = New-Object System.Management.ManagementClass($ms , ‘sms_client’,$null)
$mc.psbase.PDPMaintenanceTask
Thanks, this entry saved a lot of work!
Had a similar problem because we have a “layered” SCCM installation (development, testing, production) and want to trigger the OS deployment from a central management point. There is no trust in place between the “layers” and so you have to create the SCCM computer objects by passing credentials to the site server. Works fine using:
$ms.path = “\root\SMS\Site_”
… (provide credentials as shown above)
$mc = New-Object system.management.managementclass($ms,”SMS_Site”,$null)
$mc.ImportMachineEntry(“”,$null,”)
(replace strings inside as appropriate).
Very nice. It worked perfectly