- #region Import the Assemblies
- #----------------------------------------------
- [void][reflection.assembly]::Load('System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
- [void][reflection.assembly]::Load('System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
- #endregion Import Assemblies
- #----------------------------------------------
- #region Generated Form Objects
- #----------------------------------------------
- [System.Windows.Forms.Application]::EnableVisualStyles()
- $formChildForm = New-Object 'System.Windows.Forms.Form'
- $treeview1 = New-Object 'System.Windows.Forms.TreeView'
- $buttonOK = New-Object 'System.Windows.Forms.Button'
- $buttonCancel = New-Object 'System.Windows.Forms.Button'
- $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
- #endregion Generated Form Objects
- #----------------------------------------------
- # User Generated Script
- #----------------------------------------------
- $formChildForm_Load={
- #TODO: Initialize Form Controls here
- }
- #region Control Helper Functions
- function Get-CheckedNode
- {
- param (
- [ValidateNotNull()]
- [System.Windows.Forms.TreeNodeCollection]$NodeCollection,
- [ValidateNotNull()]
- [System.Collections.ArrayList]$CheckedNodes
- )
- foreach ($Node in $NodeCollection)
- {
- if ($Node.Checked)
- {
- [void]$CheckedNodes.Add($Node)
- }
- Get-CheckedNode $Node.Nodes $CheckedNodes
- }
- }
- #endregion
- $buttonOK_Click={
- #TODO: Place custom script here
- $CheckedNodes = New-Object System.Collections.ArrayList
- Get-CheckedNode $treeview1.Nodes $CheckedNodes
- foreach ($node in $CheckedNodes)
- {
- $Notif = $node.Name
- $Notif = $Notif.Replace("`r`n", ",")
- Write-Host $Notif
- }
- }
I have here a Tree form with checkboxes. I'm trying to make it so that after you click OK, the Name of each checked node is added to one variable, with each value separated by a comma. This variable is going to be used later on in an Invoke-Sqlcmd command. My problem is that I can't seem to get all the Names in the variable to stay on the same line and also be separated by a comma. I've tried .Replace("`r`n", ",") and -join ',' and a bunch of other stuff and nothing seems to work.