Concatenate two strings as $progressbar name

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 months and 2 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
BiocefBiocef
Posts: 2
Last visit: Thu Oct 17, 2024 2:13 am

Concatenate two strings as $progressbar name

Post by BiocefBiocef »

Hi,

In a loop I'm trying to concatenate two strings to be used as progressbar name to set (for each progressbar) the maximum value (from a counter):

My progressbar names are $progressbarDesktop, $progressbarFavorites, etc...

Code: Select all

$folders = @("Desktop", "Favorites", "Documents", "Pictures", "Music", "Downloads", "Videos")

foreach ($Folder in $folders)
{
$count= (Get-ChildItem -File -Path "C:\Users\John Doe\$folder" -recurse -attributes !H | Measure-Object).Count

$progressbar = '$progressbar' + $folder
$progressbar.Maximum = $count
}
But it does not work... ERROR: Method invocation failed because [System.String] does not contain a method named 'Maximum'.

How can do in a loop ?

Thanks for your help ! (despite my bad english)
User avatar
brittneyr
Site Admin
Posts: 1803
Last visit: Tue Nov 05, 2024 11:31 am
Answers: 44
Been upvoted: 34 times

Re: Concatenate two strings as $progressbar name

Post by brittneyr »

You only show one progress bar in this code and you are overriding it with a string.

To set the name of the control, you would do something like this:
$progressbar.Name = <value>

You may find the following links helpful:
https://info.sapien.com/index.php/guis/ ... ar-control
https://learn.microsoft.com/en-us/dotne ... work-4.8.1
Brittney
SAPIEN Technologies, Inc.
BiocefBiocef
Posts: 2
Last visit: Thu Oct 17, 2024 2:13 am

Re: Concatenate two strings as $progressbar name

Post by BiocefBiocef »

Ok so I can't use a string as a control name to use it in a loop.
Too bad it would have been practical.

Thanks for your time !
This topic is 4 months and 2 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked