Archive

Archive for the ‘Powershell’ Category

Start a Configmgr 2007 program with powershell.

March 11th, 2011 ravnda No comments

Tried to start a ConfigMgr Program with Powershell? Then you are lucky.

Here you go:

 

  1. ErrorActionPreference = "SilentlyContinue"
  2.  
  3. ##################################
  4. #        Start a advertised program with powershell.                #
  5. #                                            #
  6. #        Date: 11.06.2010                            #
  7. #        Written by Stian Ravndal                        #
  8. #        Version: 0.6.5                                #
  9. ##################################
  10.  
  11. if ($args[0] -eq "-r")
  12. {
  13. #Reading variables from registry.
  14. $parameter1 = $args[1]
  15. $registry = Get-ItemProperty "HKCU:\Software\Atea\StartApp\$parameter1"
  16.  
  17. $programID = $registry.ProgramID
  18. $PackageID = $registry.PackageID
  19. }
  20. elseif ($args[0] -eq "-s")
  21. {
  22. # Variables is inserted from parameters.
  23. $programID = $args[1]
  24. $PackageID = $args[2]
  25. }
  26. else
  27. {
  28. # This will run if no parameters are specified.
  29. # Variables inserted in script.
  30. # Package ID from ConfigMgr.
  31. $PackageID = ""
  32.  
  33. # ConfigMgr ProgramID.
  34. $programID = ""
  35. }
  36.  
  37. function startapp
  38. {
  39. param ($programID, $PackageID)
  40.  
  41. if ($programID -eq "" -OR $PackageID -eq "")
  42. {
  43. [System.Windows.Forms.MessageBox]::Show("Something wrong with parameters.")
  44. return
  45. }
  46. else
  47. {
  48. }
  49.  
  50. $startapp = New-Object -ComObject UIResource.UIResourceMgr
  51.  
  52. if ($startapp -eq $null)
  53. {
  54. [System.Windows.Forms.MessageBox]::Show("CCM client not installed.")
  55. return
  56. }
  57. if ($startapp.IsMandatoryProgramPending() -eq "1")
  58. {
  59. [System.Windows.Forms.MessageBox]::Show("There is allready something running.")
  60. return
  61. }
  62. $program = $startapp.GetProgram($programID,$PackageID)
  63. if ($program -eq $null)
  64. {
  65. [System.Windows.Forms.MessageBox]::Show("You do not have access to this program.")
  66. return
  67. }
  68. $startapp.ExecuteProgram($programID, $PackageID,"")
  69. }
  70.  
  71. startapp $programID $PackageID

Download Script

Categories: ConfigMgr2007, Powershell Tags: