我开始学习如何使用PowerShell创建工具。我已经开始创建我喜欢称之为主中心的东西,只需点击一下按钮即可找到所有其他表格。我对我创建的两个按钮有问题。当我点击解锁帐户按钮时,它会打开我的帐户解锁表单。当我单击“创建分发列表”按钮时。它会打开我的帐户解锁表单。这是我写的:
#Add in Forms Controls
Add-Type -AssemblyName System.Windows.Forms
#Image for Background and Top left icon.
$Image = [System.Drawing.Image]::FromFile("C:\Users\myname\Desktop\FormRepository\Images\imagesFJA8GNHA.jpg")
$Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($PSHOME + "\Powershell.exe")
$Font = New-Object System.Drawing.Font("Times New Roman",18)
#Begins creation of the form
$MainHub = New-Object system.Windows.Forms.Form
$MainHub.Icon = $Icon
$MainHub.Text = "My Name Forms - - - Apple Release"
$MainHub.BackgroundImage = $Image
$MainHub.BackgroundImageLayout = "Stretch"
$MainHub.Width = 1000
$MainHub.Height = 700
$Title = New-Object System.Windows.Forms.Label
$Title.Font = $Font
$Title.Text = "What do you want to do?"
$Title.Location = New-Object System.Drawing.Size(1,1)
$Title.Size = New-Object System.Drawing.Size(275,35)
$MainHub.Controls.Add($Title)
#Button Clicks
$BtnClick1 = {start-process powershell.exe '& C:\Users\myname\Desktop\Form Repository\Child Forms\UnlockADAccount.ps1'}
$BtnClick2 = {start-process powershell.exe '& C:\Users\myname\Desktop\Form Repository\Child Forms\DistributionList.ps1'}
#End Button Clicks
#Buttons
$AcctUnlock = New-Object System.Windows.Forms.Button
$AcctUnlock.Location = New-Object System.Drawing.Size(1,40)
$AcctUnlock.Size = New-Object System.Drawing.Size(200,35)
$AcctUnlock.Text = "Unlock an Account"
$AcctUnlock.Add_Click($BtnClick1)
$MainHub.Controls.Add($AcctUnlock)
$CreateDistroGroups = New-Object System.Windows.Forms.Button
$CreateDistroGroups.Location = New-Object System.Drawing.Size(1,80)
$CreateDistroGroups.Size = New-Object System.Drawing.Size(200,35)
$CreateDistroGroups.Text = "Create a Distribution List"
$CreateDistroGroups.Add_Click($BtnClick2)
$MainHub.Controls.Add($CreateDistroGroups)
#End Buttons
#Displays the Form.
$MainHub.ShowDialog()
我尝试更改变量并为按钮点击重命名它们。我已经尝试完全删除帐户解锁表单代码,以便只在表单中存在通讯组列表。即使这样,创建分发列表按钮也会打开帐户解锁表单。知道我在创建这些按钮时出错了吗?