我目前是新手,并且正在学习用于和管理目的的 powershell。我发布了这个问题,因为我在任何地方都找不到很多关于这个的信息。
我正在创建一个带有 gui 的脚本,它将我们所有的服务器列为树节点。从那里我想即时生成/填充/创建服务器的子节点(即当单击或选择节点'server1'时,它应该生成如下子节点)。由于我们有大量服务器,我不想在添加新属性时更新每台服务器上的子节点。谁能告诉我如何做到这一点?如果我的描述没有意义,我可以解释更多。
.....服务器1。. ......BIOSInfo(我通过使用标签来区分服务器节点及其子节点)。. ......PROCInfo
ETC
我正在使用带有 powershell 3.0 的 sapien 原始形式
这是示例代码;
function NodeClick( $object )
{
if ($this.SelectedNode.Tag -eq "Server")
{
$Server = $this.selectednode.text
$richTextBox1.Text = "Script for $Server Information"
#~~< TreeNode11 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TreeNode1111 = New-Object System.Windows.Forms.TreeNode("OS")
$TreeNode1111.Tag = "DevInfo"
$TreeNode1111.Text = "OS"
#~~< TreeNode12 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TreeNode1222 = New-Object System.Windows.Forms.TreeNode("Domain")
$TreeNode1222.Tag = "DevInfo"
$TreeNode1222.Text = "Domain"
#~~< TreeNode13 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TreeNode1333 = New-Object System.Windows.Forms.TreeNode("Serial")
$TreeNode1333.Tag = "DevInfo"
$TreeNode1333.Text = "Serial"
#~~< TreeNode14 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TreeNode1444 = New-Object System.Windows.Forms.TreeNode("BIOS")
$TreeNode1444.Tag = "DevInfo"
$TreeNode1444.Text = "BIOS"
#~~< TreeNode15 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TreeNode1555 = New-Object System.Windows.Forms.TreeNode("Processor")
$TreeNode1555.Tag = "DevInfo"
$TreeNode1555.Text = "Processor"
#~~< TreeNode16 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TreeNode1666 = New-Object System.Windows.Forms.TreeNode("Memory")
$TreeNode1666.Tag = "DevInfo"
$TreeNode1666.Text = "Memory"
#~~< TreeNode17 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TreeNode1777 = New-Object System.Windows.Forms.TreeNode("Partitions")
$TreeNode1777.Tag = "DevInfo"
$TreeNode1777.Text = "Partitions"
#~~< TreeNode18 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TreeNode1888 = New-Object System.Windows.Forms.TreeNode("Drive")
$TreeNode1888.Tag = "DevInfo"
$TreeNode1888.Text = "Drive"
#~~< TreeNode19 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TreeNode1999 = New-Object System.Windows.Forms.TreeNode("IPInfo")
$TreeNode1999.Tag = "DevInfo"
$TreeNode1999.Text = "IPInfo"
#~~< TreeNode110 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TreeNode2111 = New-Object System.Windows.Forms.TreeNode("PrintInfo")
$TreeNode2111.Tag = "DevInfo"
$TreeNode2111.Text = "PrintInfo"
#~~< TreeNode111 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TreeNode2222 = New-Object System.Windows.Forms.TreeNode("FolderShare")
$TreeNode2222.Tag = "DevInfo"
$TreeNode2222.Text = "FolderShare"
#~~< TreeNode112 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TreeNode2333 = New-Object System.Windows.Forms.TreeNode("Tasks")
$TreeNode2333.Tag = "DevInfo"
$TreeNode2333.Text = "Tasks"
#~~< TreeNode113 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TreeNode2444 = New-Object System.Windows.Forms.TreeNode("Services")
$TreeNode2444.Tag = "DevInfo"
$TreeNode2444.Text = "Services"
#~~< TreeNode114 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TreeNode2555 = New-Object System.Windows.Forms.TreeNode("Software")
$TreeNode2555.Tag = "DevInfo"
$TreeNode2555.Text = "Software"
$this.SelectedNode = New-Object System.Windows.Forms.TreeNode("DOCACT01", [System.Windows.Forms.TreeNode[]] ( @($TreeNode1111, $TreeNode1222, $TreeNode1333, $TreeNode1444, $TreeNode1555, $TreeNode1666, $TreeNode1777, $TreeNode1888, $TreeNode1999, $TreeNode2111, $TreeNode2222, $TreeNode2333, $TreeNode2444, $TreeNode2555) ))
$this.SelectedNode.Tag = "Server"
$this.SelectedNode.Text = "$Server"
$form1.refresh()
}
else
{
$this.SelectedNode.expand()
$richTextBox1.Text = "Script for Server Information"
}