Filter TreeView Nodes in PowerShell - winforms

I have a ton of Nodes in my TreeView, and have a textbox that filters through them to highlight the matched search. However, its a bit messy as it shows all the other nodes, and after I change my search, it leaves all nodes expanded.
I am trying to make something like this, https://www.codeproject.com/Tips/1000621/Filtering-and-Hiding-Tree-Nodes-WinForms
But I am using Windows forms / Powershell ISE and seem to struggle with implementing it into my own code.
For closing nodes I tried using things along the line of (Textbox.textlength -eq 0) to trigger a close all nodes function, but that was not working.
Here is what I want it too look like. Left is what I want, Right is what mine looks like.
Here is an example of the search function I am using.
Add-Type -AssemblyName System.Windows.Forms
function GetNodes([System.Windows.Forms.TreeNodeCollection] $nodes)
{
foreach ($n in $nodes) {
$n
GetNodes($n.Nodes)
}
}
$form = New-Object System.Windows.Forms.Form
$form.Text ="Test"
$form.Controls.AddRange(#(
($txt = [System.Windows.Forms.TextBox] #{
Location = [System.Drawing.Point]::new(8, 8);
Width = 100;
}),
($btn = [System.Windows.Forms.Button] #{
Location = [System.Drawing.Point]::new(120, 8);
Width = 50;
Text = "Search";
}),
($tree = [System.Windows.Forms.TreeView] #{
Location = [System.Drawing.Point]::new(8, 40);
Width = 170;
HideSelection = $false
})
))
$form.AcceptButton= $btn
$tree.Nodes.Add("A1", "A1")
$tree.Nodes.Add("A2", "A2")
$tree.Nodes[0].Nodes.Add("A11", "A11")
$tree.Nodes[0].Nodes.Add("A12", "A12")
$tree.Nodes[1].Nodes.Add("A21", "A21")
$tree.Nodes[1].Nodes.Add("A22", "A22")
$btn.Add_Click({param($sender,$e)
$nodes = GetNodes($tree.Nodes)
foreach ($node in $nodes) {
if($node.Text -like $txt.Text){
$tree.SelectedNode = $node
$node.EnsureVisible()
break
}
}
})
$form.ShowDialog() | Out-Null
$form.Dispose()

Assuming you are searching on a data source like a folder structure, this is what I'll do:
Create a function to get list of all directories recursively into a list
Create a function to filter the list of directories and return a list of directories which contain a specific text in their names.
Create a function to populate treeview
create a function to highlight treenode if it contains a specific text
Then in the text-changed event of the textbox, I'll filter and highlight tree:
Here is the code:
Add-Type -AssemblyName System.Windows.Forms
function GetPaths($root)
{
Get-ChildItem $root -Recurse -Directory | % {
$_.FullName.Replace($root, "").Trim("\")}
}
function FilterPaths($paths, $like)
{
$paths | ? {$_ -like "*$like*"} | % {
$i = $_.LastIndexOf("$like", [System.Globalization.CompareOptions]::IgnoreCase)
if($i -gt -1) {
$j = $_.IndexOf("\", $i, [System.Globalization.CompareOptions]::IgnoreCase)
if($j -gt -1) {
$_.SubString(0,$j)
} else {
$_
}
}
}
}
function GetNodes($nodes)
{
foreach ($n in $nodes) {
$n
GetNodes($n.Nodes)
}
}
function HighlightNodes($nodes, $like)
{
if(!$like){ return }
$nodes | ? {$_ -like "*$like*"} | % {
$_.BackColor = "Yellow"
}
}
function PopulateTree($treeView, $paths)
{
$treeView.Nodes.Clear()
foreach ($path in $paths)
{
$lastNode = $null
$subPathAgg = ""
foreach ($subPath in ($path -split '\\'))
{
$subPathAgg += ($subPath + '\')
$nodes = $treeView.Nodes.Find($subPathAgg, $true)
if ($nodes.Length -eq 0) {
if ($lastNode -eq $null) {
$lastNode = $treeView.Nodes.Add($subPathAgg, $subPath)
} else {
$lastNode = $lastNode.Nodes.Add($subPathAgg, $subPath)
}
} else {
$lastNode = $nodes[0]
}
}
}
}
$form = New-Object System.Windows.Forms.Form
$form.Text ="Test"
$form.Controls.AddRange(#(
($txt = [System.Windows.Forms.TextBox] #{
Location = [System.Drawing.Point]::new(8, 8);
Width = $form.ClientSize.Width - 16;
Anchor = [System.Windows.Forms.AnchorStyles]13
}),
($tree = [System.Windows.Forms.TreeView] #{
Location = [System.Drawing.Point]::new(8, 40);
Width = $form.ClientSize.Width - 16;
Anchor = [System.Windows.Forms.AnchorStyles]15
Height = 200;
HideSelection = $false
})
))
$form.AcceptButton= $btn
$root = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp"
$paths = GetPaths $root
PopulateTree $tree $paths
$tree.ExpandAll()
$txt.Add_TextChanged({param($sender,$e)
$tree.BeginUpdate()
$like = $txt.Text
$filtered = FilterPaths $paths $like
PopulateTree $tree $filtered
HighlightNodes (GetNodes $tree.Nodes) $like
$tree.ExpandAll()
$tree.TopNode = $tree.Nodes[0]
$tree.EndUpdate()
})
$form.ShowDialog() | Out-Null
$form.Dispose()

Related

Powershell winform ListView right mouse button context menu binding to specific ListView item

I'm trying to create clicks for right mouse button which are specific to each item in the listview to be able to execute commands on remote pc. I just don't know how assign the separate context menu to a specific ListViewItem.
I have tried to create form also with an array but I have bumped to the same problem and I don't know how to formulate the problem to search for it on internet.
Thanks for help!
Here is the code:
## Set up the environment
Add-Type -AssemblyName System.Windows.Forms
$LastColumnClicked = 0 # tracks the last column number that was clicked
$LastColumnAscending = $false # tracks the direction of the last sort of this column
## Create a form and a ListView
$Form = New-Object System.Windows.Forms.Form
$ListView = New-Object System.Windows.Forms.ListView
## Configure the form
$Form.Text = "Computer List"
## Configure the ListView
$ListView.View = [System.Windows.Forms.View]::Details
$ListView.Width = $Form.ClientRectangle.Width
$ListView.Height = $Form.ClientRectangle.Height
$ListView.Anchor = "Top, Left, Right, Bottom"
# Add the ListView to the Form
$Form.Controls.Add($ListView)
# Add columns to the ListView
$ListView.Columns.Add("Computer Name", -2) | Out-Null
$ListView.Columns.Add(" Test") | Out-Null
# Add list items
$contextMenuStrip = [System.Windows.Forms.ContextMenuStrip]#{}
$listView.Font = 'Microsoft Sans Serif,10'
##Computer1##
$ListViewItem = New-Object System.Windows.Forms.ListViewItem("computer1")
$click1 = {Invoke-Command -UseSSL -ComputerName computer1 }
$click2 = {Invoke-Command -UseSSL -ComputerName computer1 }
$item1 = $contextMenuStrip.Items.Add("Run 1")
$item1.add_Click($click1)
$item2 = $contextMenuStrip.Items.Add("Run 2")
$item2.add_Click($click2)
$listView.Add_MouseClick({param($sender,$e)
if ($e.Button -eq [System.Windows.Forms.MouseButtons]::Right){
if ($listView.FocusedItem.GetBounds(
[System.Windows.Forms.ItemBoundsPortion]::Entire).Contains($e.Location)){
$contextMenuStrip.Show([System.Windows.Forms.Cursor]::Position)
}
}
})
$ListView.Items.Add($ListViewItem) | Out-Null
##computer2##
$contextMenuStrip = [System.Windows.Forms.ContextMenuStrip]#{}
$ListViewItem = New-Object System.Windows.Forms.ListViewItem("computer2")
$click1 = {Invoke-Command -UseSSL -ComputerName computer2 }
$click2 = {Invoke-Command -UseSSL -ComputerName computer2 }
$item1 = $contextMenuStrip.Items.Add("Run 3")
$item1.add_Click($click1)
$item2 = $contextMenuStrip.Items.Add("Run 4")
$item2.add_Click($click2)
$listView.Add_MouseClick({param($sender,$e)
if ($e.Button -eq [System.Windows.Forms.MouseButtons]::Right){
if ($listView.FocusedItem.GetBounds(
[System.Windows.Forms.ItemBoundsPortion]::Entire).Contains($e.Location)){
$contextMenuStrip.Show([System.Windows.Forms.Cursor]::Position)
}
}
})
$ListView.Items.Add($ListViewItem) | Out-Null
## Set up the event handler
$ListView.add_ColumnClick({SortListView $_.Column})
## Event handler
function SortListView
{
param([parameter(Position=0)][UInt32]$Column)
$Numeric = $true # determine how to sort
# if the user clicked the same column that was clicked last time, reverse its sort order. otherwise, reset for normal ascending sort
if($Script:LastColumnClicked -eq $Column)
{
$Script:LastColumnAscending = -not $Script:LastColumnAscending
}
else
{
$Script:LastColumnAscending = $true
}
$Script:LastColumnClicked = $Column
$ListItems = #(#(#())) # three-dimensional array; column 1 indexes the other columns, column 2 is the value to be sorted on, and column 3 is the System.Windows.Forms.ListViewItem object
foreach($ListItem in $ListView.Items)
{
# if all items are numeric, can use a numeric sort
if($Numeric -ne $false) # nothing can set this back to true, so don't process unnecessarily
{
try
{
$Test = [Double]$ListItem.SubItems[[int]$Column].Text
}
catch
{
$Numeric = $false # a non-numeric item was found, so sort will occur as a string
}
}
$ListItems += ,#($ListItem.SubItems[[int]$Column].Text,$ListItem)
}
# create the expression that will be evaluated for sorting
$EvalExpression = {
if($Numeric)
{ return [Double]$_[0] }
else
{ return [String]$_[0] }
}
# all information is gathered; perform the sort
$ListItems = $ListItems | Sort-Object -Property #{Expression=$EvalExpression; Ascending=$Script:LastColumnAscending}
## the list is sorted; display it in the listview
$ListView.BeginUpdate()
$ListView.Items.Clear()
foreach($ListItem in $ListItems)
{
$ListView.Items.Add($ListItem[1])
}
$ListView.EndUpdate()
}
## Show the form
$Response = $Form.ShowDialog()
})
$ListView.Items.Add($ListViewItem) | Out-Null

How do I add Checked Items from a CheckedListBox to a Combobox (dropdown) and remove them from the Combobox when unchecked?

I should start by saying that i'm new to PowerShell and i'm still in the learning phase. I've hit a road block and any help would be appreciated.
I have the following code:
# LOAD WINFORMS ASSEMBLY
[reflection.assembly]::LoadWithPartialName( "System.Windows.Forms")
[reflection.assembly]::LoadWithPartialName( "System.Drawing")
# CREATE FORMS
$Form = New-Object Windows.Forms.Form
$Form.text = "Post-Image Configuration Tool"
$Form.Width = 900
$Form.Height = 560
$Form.BackColor = "#3a73b8"
$Form.ForeColor = "White"
$Form.FormBorderStyle = "None"
$Form.StartPosition = "CenterScreen"
# START NETWORK CONFIGURATION PAGE
$GetConnectedAdapters = Get-WmiObject -Class Win32_NetworkAdapter -Filter "NetConnectionStatus = 2" | Select-Object NetConnectionID, Name, MACAddress
$netConfigList1 = New-Object System.Windows.Forms.CheckedListBox
$netConfigList1.Location = New-Object System.Drawing.Size(310,300)
$netConfigList1.Size = New-Object System.Drawing.Size(480,180)
$netConfigList1.Height = 100
$netConfigList1.BackColor = "#3a73b8"
$netConfigList1.ForeColor = "White"
$netConfigList1.BorderStyle = "None"
$netConfigList1.Font = $ListFont
$netConfigList1.add_SelectedIndexChanged({ListNetAdapters})
$netConfigListAdapters = #()
ForEach ($i in $GetConnectedAdapters.NetConnectionID){
$GetAdapterName = Get-WmiObject -Class Win32_NetworkAdapter |Where {$_.NetConnectionID -eq $i} | Select-Object Name, NetConnectionID, MACAddress
$AdapterName = $i +" - " + "("+ $GetAdapterName.Name +")"
$netConfigListAdapters += ,$AdapterName
}
$netConfigList1.Items.AddRange($netConfigListAdapters)
$netConfigSubtext5 = New-Object Windows.Forms.Label
$netConfigSubtext5.Location = New-Object Drawing.Point 290,400
$netConfigSubtext5.Size = New-Object Drawing.Point 590,20
$netConfigSubtext5.text = "• Select the Standby Adapter:"
$netConfigSubtext5.font = $SubTextFont
$netConfigComboBox1 = New-Object System.Windows.Forms.ComboBox
$netConfigComboBox1.Location = New-Object System.Drawing.Size(310,420)
$netConfigComboBox1.Size = New-Object System.Drawing.Size(260,20)
$netConfigComboBox1.Font = $SubTextFont
$netConfigComboBox1.DropDownStyle = "DropDownList"
[void] $netConfigComboBox1.Items.Add("None (All Adapters Active)")
$NetConfiguration = $netConfigList1,$netConfigSubtext5,$netConfigComboBox1
# CREATE FUNCTIONS
Function ListNetAdapters
{
$RemoveItems = #()
$AddItems = #()
for($index =0; $index -lt $netConfigList1.Items.Count; $index++)
{
$test = $netConfigList1.Items | Where-Object { $netConfigList1.Items.IndexOf($index) }
if($netConfigList1.GetItemChecked($index) -AND $netConfigComboBox1.Items -notcontains $test)
{
$AddItems += ,$test
}
ForEach($i in $netConfigComboBox1.Items){
IF(($netConfigList1.CheckedItems -notcontains $i) -AND ($i -ne 'None (All Adapters Active)')){$RemoveItems += ,$i}
}
}
ForEach ($i in $RemoveItems){$netConfigComboBox1.Items.Remove($i)}
ForEach ($i in $AddItems){$netConfigComboBox1.Items.Add($i)}
}
Function AddNetConfiguration
{
ForEach ($i in $NetConfiguration){$form.controls.add($i)}
}
AddNetConfiguration
# DISPLAY FORM
$form.ShowDialog()
Basically, what i'm trying to accomplish is exactly what you would see in the Advanced Settings of a NIC Team in Windows Server 2012/2012 R2. I want the network adapters selected in the CheckedListBox to populate in the ComboBox and be removed if unchecked.
I've installed WMF 4.0 on my Windows 7 PC and this seems to work well, but I get "System.Object[]" in Windows Server 2012. So i'm apparently missing the big picture or doing something wrong.
Windows Server 2012 comes with PowerShell v3.0, you have to make it to WMF4.0
Answer moved from question by editor
I was able to get it working after I fixed the $ListNetAdapters function. I think I was over complicating it before.
Function ListNetAdapters
{
$RemoveItems = #()
$AddItems = #()
ForEach($checkedItem in $netConfigList1.CheckedItems){
IF($netConfigComboBox1.Items -notcontains $checkedItem){$AddItems += ,$checkedItem}
}
ForEach($item2Badded in $AddItems){$netConfigComboBox1.Items.Add($item2Badded)}
ForEach($dropdownItem in $netConfigComboBox1.Items){
IF($netConfigList1.CheckedItems -notcontains $dropdownItem){$RemoveItems += ,$dropdownItem}
}
ForEach($item2Bremoved in $RemoveItems){
IF($item2Bremoved -ne 'None (All Adapters Active)'){$netConfigComboBox1.Items.Remove("$item2Bremoved")}
}
}

recursive function - array values disappears

Before calling a recursive function (RecursiveWebs()) $webinfo.Count is 1. During the execution of recursive function, Count is increased, but as soon as the recursive function is completed and control returns to the main function, $webinfo.Count again decreases to 1.
function RecursiveWebs($web) {
$Properties = #{
Title = $web.Title
URL = $web.Url
}
$webinfo += New-Object PSObject -Property $properties
foreach ($w in $web.Webs) {
if ($w.Webs.Count -gt 0) {
RecursiveWebs $w
}
}
}
$global:webinfo = #()
$sites = Get-SPOSite -Limit All
foreach ($site in $sites) {
Write-Host $site.Url
try {
$Properties = #{
Title = $site.Title
URL = $site.Url
NoOfSubsites = $site.Webs.Count
}
$webinfo += New-Object PSObject -Property $properties
if ($site.Webs.Count -gt 0) {
RecursiveWebs $site
}
} catch {
Write-Host $_ -ForegroundColor Red
}
}
Replaces $webinfo with $Global:webinfo everywhere in the code and it did the trick

ListView Sort doesn't work OnClick (PowerShell)

I have a ListView on a form built in PowerShell which I just can't get sorted.
If I call $LV.Sort() from the command line (while the form is not shown) it works perfectly fine. However if I try to call it in an OnClick event on anything on the form it doesn't. I've put flags in and I know that section of code is running, it's just not doing anything or flagging any errors.
Obviously $LV.Sorting = "Ascending" is set otherwise it wouldn't be sorting at all, and I can change the items so the reference to the ListView is fine. Also tried invoking in case of a threading issue but no different.
Annoyingly this is a tricky subject to research due to so many people forgetting to set the Sorting property.
EDIT: Not sure if relevant but the form is called with ShowDialog()
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$form = New-Object System.Windows.Forms.Form
$LVserverlist = New-Object System.Windows.Forms.ListView
$form.Controls.Add($LVserverlist)
$LVserverlist.Dock = "Fill"
$LVserverlist.View = "Details"
$LVserverlist.Sorting = "Ascending"
$LVserverlist.Add_ColumnClick({ $LVserverlist.sort(); $LVserverlist.Items[0].Text = "Working?" })
$LVserverlist.Columns.Add("Name", 200, "Left") | Out-Null
0..10 | Foreach-Object {
$LVItem = New-Object System.Windows.Forms.ListViewItem
$LVItem.Text = (Get-Random -Maximum 1000).ToString()
$LVserverlist.Items.Add($LVItem) | Out-Null
}
$form.ShowDialog()
You can try with custom function Sort-ListViewColumn
$MyListView.Add_ColumnClick({
param($sender,$e)
# Sort as Text String (not [int])
Sort-ListViewColumn -ListView $this -ColumnIndex $e.column
})
full function code :
function Sort-ListViewColumn
{
<#
.SYNOPSIS
Sort the ListView's item using the specified column.
.DESCRIPTION
Sort the ListView's item using the specified column.
This function uses Add-Type to define a class that sort the items.
The ListView's Tag property is used to keep track of the sorting.
.PARAMETER ListView
The ListView control to sort.
.PARAMETER ColumnIndex
The index of the column to use for sorting.
.PARAMETER SortOrder
The direction to sort the items. If not specified or set to None, it will toggle.
.EXAMPLE
Sort-ListViewColumn -ListView $listview1 -ColumnIndex 0
.NOTES
SAPIEN Technologies, Inc.
http://www.sapien.com/
#>
param (
[ValidateNotNull()]
[Parameter(Mandatory = $true)]
[System.Windows.Forms.ListView]$ListView,
[Parameter(Mandatory = $true)]
[int]$ColumnIndex,
[System.Windows.Forms.SortOrder]$SortOrder = 'None')
if (($ListView.Items.Count -eq 0) -or ($ColumnIndex -lt 0) -or ($ColumnIndex -ge $ListView.Columns.Count))
{
return;
}
#region Define ListViewItemComparer
try
{
$local:type = [ListViewItemComparer]
}
catch
{
Add-Type -ReferencedAssemblies ('System.Windows.Forms') -TypeDefinition #"
using System;
using System.Windows.Forms;
using System.Collections;
public class ListViewItemComparer : IComparer
{
public int column;
public SortOrder sortOrder;
public ListViewItemComparer()
{
column = 0;
sortOrder = SortOrder.Ascending;
}
public ListViewItemComparer(int column, SortOrder sort)
{
this.column = column;
sortOrder = sort;
}
public int Compare(object x, object y)
{
if(column >= ((ListViewItem)x).SubItems.Count)
return sortOrder == SortOrder.Ascending ? -1 : 1;
if(column >= ((ListViewItem)y).SubItems.Count)
return sortOrder == SortOrder.Ascending ? 1 : -1;
if(sortOrder == SortOrder.Ascending)
return String.Compare(((ListViewItem)x).SubItems[column].Text, ((ListViewItem)y).SubItems[column].Text);
else
return String.Compare(((ListViewItem)y).SubItems[column].Text, ((ListViewItem)x).SubItems[column].Text);
}
}
"# | Out-Null
}
#endregion
if ($ListView.Tag -is [ListViewItemComparer])
{
#Toggle the Sort Order
if ($SortOrder -eq [System.Windows.Forms.SortOrder]::None)
{
if ($ListView.Tag.column -eq $ColumnIndex -and $ListView.Tag.sortOrder -eq 'Ascending')
{
$ListView.Tag.sortOrder = 'Descending'
}
else
{
$ListView.Tag.sortOrder = 'Ascending'
}
}
else
{
$ListView.Tag.sortOrder = $SortOrder
}
$ListView.Tag.column = $ColumnIndex
$ListView.Sort()#Sort the items
}
else
{
if ($Sort -eq [System.Windows.Forms.SortOrder]::None)
{
$Sort = [System.Windows.Forms.SortOrder]::Ascending
}
#Set to Tag because for some reason in PowerShell ListViewItemSorter prop returns null
$ListView.Tag = New-Object ListViewItemComparer ($ColumnIndex, $SortOrder)
$ListView.ListViewItemSorter = $ListView.Tag #Automatically sorts
}
}
Never did find a solution to getting Sort() to work, ended up with this workaround (which is a bit more flexible anyway):
Param
(
[System.Windows.Forms.ListView]$sender,
$column
)
$temp = $sender.Items | Foreach-Object { $_ }
$sender.Items.Clear()
$sender.Items.AddRange(($temp | Sort-Object -Property #{ Expression={ $_.SubItems[$column].Text } }))
Note that on the ListView the Sorting property needs to be set to None otherwise the items will be added back alphabetically.
coller event
$MyListView.add_ColumnClick({SortListView $this $_.Column})
Sort function whit memorize the lastest Order :
function SortListView {
Param(
[System.Windows.Forms.ListView]$sender,
$column
)
$temp = $sender.Items | Foreach-Object { $_ }
$Script:SortingDescending = !$Script:SortingDescending
$sender.Items.Clear()
$sender.ShowGroups = $false
$sender.Sorting = 'none'
$sender.Items.AddRange(($temp | Sort-Object -Descending:$script:SortingDescending -Property #{ Expression={ $_.SubItems[$column].Text } }))
}

How to append to powershell Hashtable value?

I am interating through a list of Microsoft.SqlServer.Management.Smo.Server objects and adding them to a hashtable like so:
$instances = Get-Content -Path .\Instances.txt
$scripts = #{}
foreach ($i in $instances)
{
$instance = New-Object Microsoft.SqlServer.Management.Smo.Server $i
foreach($login in $instance.Logins)
{
$scripts.Add($instance.Name, $login.Script())
}
}
So far so good. What I want to do now is append a string to the end of the hashtable value. So for an $instance I want to append a string to the hashtable value for that $instance. How would I do that? I have started with this, but I'm not sure if I'm on the right track:
foreach ($db in $instance.Databases)
{
foreach ($luser in $db.Users)
{
if(!$luser.IsSystemObject)
{
$scripts.Set_Item ($instance, <what do I add in here?>)
}
}
}
Cheers
$h= #{}
$h.add("Test", "Item")
$h
Name Value
---- -----
Test Item
$h."Test" += " is changed"
$h
Name Value
---- -----
Test Item is changed
I would go with this code.
$instances = Get-Content -Path .\Instances.txt
$scripts = #{}
foreach ($i in $instances)
{
$instance = New-Object Microsoft.SqlServer.Management.Smo.Server $i
foreach($login in $instance.Logins)
{
$scripts[$instance.Name] = #($scripts[$instance.Name]) + $login.Script().ToString()
}
}
.
foreach ($db in $instance.Databases)
{
foreach ($luser in $db.Users)
{
if(!$luser.IsSystemObject)
{
$scripts[$instance] = #($scripts[$instance]) + $luser.Script().ToString()
}
}
}
The result will be a hash table with each instance as a key, and an array of strings where each string is the T-SQL script for a user.
The .Script() method returns a string collection. There's probably a more elegant way of doing it, but replacing
$scripts.Set_Item ($instance, <what do I add in here?>)
with
$val = $scripts[$instance]
$val.Add("text to add")
$scripts.Set_Item($instance, $val)
should work.
$test = #{}
$test.Hello = "Hello World"
Write-Host "message from $($test.Hello)"
$test.Hello += " Cosmonaut"
Write-Host "message from $($test.Hello)"

Resources