如何将某些值转换为SCCM使用的变量?

问题描述

我想知道是否有人可以向我指出正确的方向,或者给我提供文档链接,以使它尽可能地起作用。

当前,我们正在使用Powershell窗口表单来创建菜单(GUI),以便帮助台可以更轻松地通过SCCM部署新计算机。 Powershell脚本是启动任务序列时运行的第一步。代码如下所示:

<# This form was created using POSHGUI.com  a free online gui designer for PowerShell
.NAME
    Untitled
#>

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

$Form                            = New-Object system.Windows.Forms.Form
$Form.ClientSize                 = New-Object System.Drawing.Point(632,264)
$Form.text                       = "Contoso"
$Form.TopMost                    = $false

$OSDComputername1                = New-Object system.Windows.Forms.TextBox
$OSDComputername1.multiline      = $false
$OSDComputername1.width          = 100
$OSDComputername1.height         = 20
$OSDComputername1.location       = New-Object System.Drawing.Point(120,43)
$OSDComputername1.Font           = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$Label1                          = New-Object system.Windows.Forms.Label
$Label1.text                     = "Computer naam:"
$Label1.AutoSize                 = $true
$Label1.width                    = 25
$Label1.height                   = 10
$Label1.location                 = New-Object System.Drawing.Point(13,43)
$Label1.Font                     = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$Label2                          = New-Object system.Windows.Forms.Label
$Label2.text                     = "Selecteer taal:"
$Label2.AutoSize                 = $true
$Label2.width                    = 25
$Label2.height                   = 10
$Label2.location                 = New-Object System.Drawing.Point(13,15)
$Label2.Font                     = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$OSDLang1                        = New-Object system.Windows.Forms.ComboBox
$OSDLang1.text                   = "Taal"
$OSDLang1.width                  = 100
$OSDLang1.height                 = 20
@('NL','EN') | ForEach-Object {[void] $OSDLang1.Items.Add($_)}
$OSDLang1.location               = New-Object System.Drawing.Point(120,15)
$OSDLang1.Font                   = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$Label3                          = New-Object system.Windows.Forms.Label
$Label3.text                     = "BTO:"
$Label3.AutoSize                 = $true
$Label3.width                    = 25
$Label3.height                   = 10
$Label3.location                 = New-Object System.Drawing.Point(13,91)
$Label3.Font                     = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$BTO1                            = New-Object system.Windows.Forms.CheckBox
$BTO1.text                       = "Installeer BTO gerelateerde software tijdens Task Seuqence"
$BTO1.AutoSize                   = $false
$BTO1.width                      = 409
$BTO1.height                     = 20
$BTO1.location                   = New-Object System.Drawing.Point(120,89)
$BTO1.Font                       = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$Label4                          = New-Object system.Windows.Forms.Label
$Label4.text                     = "NA18JULI:"
$Label4.AutoSize                 = $true
$Label4.width                    = 25
$Label4.height                   = 10
$Label4.location                 = New-Object System.Drawing.Point(13,115)
$Label4.Font                     = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$NA18JULI1                       = New-Object system.Windows.Forms.CheckBox
$NA18JULI1.text                  = "Computer aankoopdatum na 18 Juli 2018"
$NA18JULI1.AutoSize              = $false
$NA18JULI1.width                 = 371
$NA18JULI1.height                = 20
$NA18JULI1.location              = New-Object System.Drawing.Point(120,115)
$NA18JULI1.Font                  = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$Annuleren                       = New-Object system.Windows.Forms.Button
$Annuleren.text                  = "Annuleren"
$Annuleren.width                 = 85
$Annuleren.height                = 38
$Annuleren.location              = New-Object System.Drawing.Point(516,188)
$Annuleren.Font                  = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$Volgende                        = New-Object system.Windows.Forms.Button
$Volgende.text                   = "Volgende"
$Volgende.width                  = 85
$Volgende.height                 = 38
$Volgende.location               = New-Object System.Drawing.Point(29,188)
$Volgende.Font                   = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$Form.controls.AddRange(@($OSDComputername1,$Label1,$Label2,$OSDLang1,$Label3,$BTO1,$Label4,$NA18JULI1,$Annuleren,$Volgende))

$Annuleren.Add_MouseClick({ Shutdown })
$Volgende.Add_MouseClick({ Continue1 })

function Shutdown {wpeutil shutdown}
function Continue1 {$Form.Close()}

[void]$Form.ShowDialog()

#Write your logic code here

$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment

$tsenv.Value('OSDComputerName') = $OSDComputername1.Text
$tsenv.Value('OSDLang') = $OSDLang1.Text

if ($BTO1.checked) {
    $tsenv.Value('BTO') = "JA"
}
else {
    $tsenv.Value('BTO') = "NEE"
}

if ($NA18JULI1.checked) {
    $tsenv.Value('NA18JULI') = "JA"
}
else {
    $tsenv.Value('NA18JULI') = "NEE"
}

尽管这种方法在一定程度上可以解决(笔记本电脑等出现奇怪的字体问题),但是我遇到了在Visual Studio中创建Windows Form Apps的功能。问题是,这是用C#编写的,我的知识不存在。设计器在设计表单时非常直观,我有几个按钮可以使用所需的特定命令。到目前为止,代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Contoso
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Volgende(object sender,MouseEventArgs e)
        {
           
        }

        private void Volgende1_Click(object sender,EventArgs e)
        {
             System.Windows.Forms.Application.Exit();
        }

        private void Afsluiten1_Click(object sender,EventArgs e)
        {
            System.Diagnostics.Process.Start("wpeutil reboot");
        }

        private void OSDLang1_SelectedindexChanged(object sender,EventArgs e)
        {

        }

        private void OSDComputername1_TextChanged(object sender,EventArgs e)
        {

        }

        private void BTO1_CheckedChanged(object sender,EventArgs e)
        {

        }

        private void NA18JULI1_CheckedChanged(object sender,EventArgs e)
        {

        }
    }
}

在接下来的步骤是使用OSDLang1的(这是一个组合框,所以,当EN选自例如)或OSDComputername1(服务台输入的计算机的名称,例如CI-1234)所选择的值,并将其放置在工作序列变量。例如,我使用Powershell:

$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment

$tsenv.Value('OSDComputerName') = $OSDComputername1.Text
$tsenv.Value('OSDLang') = $OSDLang1.Text

是否有一种方法可以使此方法与c#一起使用。就像我说的那样,没有必要完全回答这个问题,但是任何可以阅读此工作原理的文档都可以。

预先感谢

GarySappig

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)