none
Microsoft.SMS.TSEnvironment Object RRS feed

  • 问题

  • Helou,

    pls, I need a help with PS code.

    I have a simple guy script and my goal is, install all checked applications... So, if is checked App1 and App5 CheckBoxes, this 2 Apps will be installed. Simple easy I guess...

    But I'm stucked in Microsoft.SMS.TSEnvironment Object and I don't know how to contrinue:

    Here is a part of code 

    $StartButton = New-Object System.Windows.Forms.Button
    $StartButton.Location = New-Object System.Drawing.Size(135,460)
    $StartButton.Size = New-Object System.Drawing.Size(100,25)
    $StartButton.Text = "Start Install"
    $StartButton.Font = New-Object System.Drawing.Font("Arial",9,[System.Drawing.FontStyle]::Regular)
    $StartButton.Add_Click({
        $Applications = @($App1, $App2, $App3, $App4, $App5, $App6) 
        foreach($CheckedApplications in $Applications){
            if ($CheckedApplications.Checked) {
              #SCCM Code
              $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment
              $TSEnv.Value(? HELP ^^ ?)
            }    
        }
    })
     

    If is checkbox checked, he return a "TRUE". How can I Add a 'Install Application' step from TS for checked Apps?

    Or create a new variable for checked checkboxes and Import this variable to TakSequence?

    Hope you understand me. :) 


    2019年11月22日 10:04

答案

  • First, take this line out for the foreach loop: $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment. You don't want to create the COM object over and over again.

    Next, to set a variables value, you simply need to run the following:

    $TSEnv.Value("VariableName") = "VariableValue"

    VariableValue for each iteration needs to be the name of the Application in ConfigMgr.

    So, what you need is something like this where the VariableName is SelectApplication01, SlectedAPplication02, etc. This also assumes that there is a Text attribute on the $App1, $App2, etc. variables containing the ConfigMgr Application name.

    $StartButton.Add_Click({ $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment $Applications = @($App1, $App2, $App3, $App4, $App5, $App6)

    $AppCount = 1

    foreach($CheckedApplication in $Applications){ if ($CheckedApplication.Checked) { $TSEnv("SelectedApplication0$AppCount") = $CheckedApplication.Text $AppCount++ } } })




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


    2019年11月22日 14:08

全部回复

  • First, take this line out for the foreach loop: $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment. You don't want to create the COM object over and over again.

    Next, to set a variables value, you simply need to run the following:

    $TSEnv.Value("VariableName") = "VariableValue"

    VariableValue for each iteration needs to be the name of the Application in ConfigMgr.

    So, what you need is something like this where the VariableName is SelectApplication01, SlectedAPplication02, etc. This also assumes that there is a Text attribute on the $App1, $App2, etc. variables containing the ConfigMgr Application name.

    $StartButton.Add_Click({ $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment $Applications = @($App1, $App2, $App3, $App4, $App5, $App6)

    $AppCount = 1

    foreach($CheckedApplication in $Applications){ if ($CheckedApplication.Checked) { $TSEnv("SelectedApplication0$AppCount") = $CheckedApplication.Text $AppCount++ } } })




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


    2019年11月22日 14:08
  • Hi Jason, thanks for reply.

    I'm sorry but I don't understand.

    Why VariableValue need to be the name of the Application in ConfigMgr?

    If I create 

    $TSEnv.Value("PowerBI") = $CheckBoxPowerBI.Text

    $SelectedApp =$TSEnv.Value("PowerBI")

    $SelectedApp will contain the: "$CheckBoxPowerBI.Text" (Power BI)

    So why it needs to be the name of the Application in ConfigMgr?

    And the $AppCount = 1

    You mean creat $TSEnv.Value() for every application? ^^

    This part is confusing me xD 

    2019年11月22日 16:58
  • Why VariableValue need to be the name of the Application in ConfigMgr?

    If you are using the Install Application step along with a dynamic variable list, you need to populate the variables in that list with the name of the Application. Thus, if the user checks all six check-boxes, it creates the following variables:

    SelectedApplication01 = "PowerBI"

    SelectedApplication02 = "Chrome"

    SelectedApplication03 = "Firefox"

    SelectedApplication04 = "7-zip"

    SelectedApplication05 = "Microsoft Office"

    SelectedApplication06 = "Visual Studio Code"

    Then, in your Install Software task, you choose the bottom radio button and specify SelectedApplication as the variable list base.


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

    2019年11月22日 17:03
  • I would use UI++ (http://uiplusplus.configmgrftw.com/) to generate your form for app selection. You then have a simple xml file to edit to save those selections as TS variables. Quick and Easy. You can run the ui++ binary  from a unc path or save it in your boot image and select the apps at the start of the sequence. Just some food for thought...   

    ;-) - Jason might be able to elaborate more...


    Thanks, Brady

    2019年11月26日 13:35
  • Helou :) 

    I'm sorry for not replying, but I got a little bit sick.

    Thanks for nice example and good explanation, Jason!

    Everything works like charm now.

    Thanks again ^^

    2019年11月26日 17:44