Powershell结构“包装”代码块而不会移动范围

时间:2017-09-19 06:55:41

标签: powershell scope structure

由于我的脚本变得越来越长而且会越来越长,我想知道是否可以在不改变范围或值的情况下包装一些代码块。

我在html上讨论像div容器这样的东西,甚至只是用c语言包装“int main(void)”之类的东西

#Select which option Form

$form = New-Object System.Windows.Forms.Form 
$form.Text = "CSV Liste"
$form.Size = New-Object System.Drawing.Size(300,300) 
$form.StartPosition = "CenterScreen"

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(75,195)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point(150,195)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $CancelButton
$form.Controls.Add($CancelButton)

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20) 
$label.Size = New-Object System.Drawing.Size(280,20) 
$label.Text = "Welche CSV Liste soll geladen werden:"
$form.Controls.Add($label) 

$listBox = New-Object System.Windows.Forms.ListBox 
$listBox.Location = New-Object System.Drawing.Point(10,40) 
$listBox.Size = New-Object System.Drawing.Size(260,20) 
$listBox.Height = 150

[void] $listBox.Items.Add("AS400 Computer")
[void] $listBox.Items.Add("AS400 Personalstamm")
[void] $listBox.Items.Add("ADComputer")
[void] $listBox.Items.Add("ADBenutzer")

#Formclosed

这将是我的脚本中的一个完美部分,可以像div容器一样包装以获得一些结构,但我不知道是否有这样的选项而不改变范围

1 个答案:

答案 0 :(得分:2)

如果您使用PowerShell ISE,则可以使用#region

enter image description here

现在您可以折叠每个区域。你也可以嵌套它们。