Avatar of Kelly Garcia
Kelly Garcia
Flag for United Kingdom of Great Britain and Northern Ireland asked on

store items in variable - Powershell

Hi All,

I have this line of code in my script:

if ($null -ne $ListView.SelectedItems) {
        $ListView.ItemsSource = @($ListView.SelectedItems | Select-Object DisplayName, TotalItemSize, ItemCount, Database, TotalDeletedItemSize,DeletedItemCount, LastLoggedOnUserAccount, LastLogonTime, LastLogoffTime -OutVariable $mailboxtomigrate)
		$m = $mailboxtomigrate | Out-String
		[System.Windows.MessageBox]::Show("$m")

Open in new window


the selected can be many. I need to store it in a variable so I can loop through it when I run the new-moverequest script.

so I need the display names to be stored as a string in the variable e.g. $mailboxtomigrate = "display name 1", "display name 2", "display name 3"

how do I do this?

is better if I out the results into an array?  how do I do this?

thank you in advance
PowershellExchange* WPF

Avatar of undefined
Last Comment
Kelly Garcia

8/22/2022 - Mon
Raheman M. Abdul

if ($null -ne $ListView.SelectedItems) {
        $ListView.ItemsSource = @($ListView.SelectedItems | Select-Object DisplayName, TotalItemSize, ItemCount, Database, TotalDeletedItemSize,DeletedItemCount, LastLoggedOnUserAccount, LastLogonTime, LastLogoffTime )
		$m = $ListView.ItemsSource  | Out-String
		[System.Windows.MessageBox]::Show("$m")

Open in new window

Chris Dent

I think this will never actually be null:
if ($null -ne $ListView.SelectedItems) {

Open in new window

On reflection, it might be better to make the comparison:
if ($ListView.SelectedItems.Count -eq 0) {

Open in new window

How are you launching the code to migrate? I will continue to argue that you do not need to store these in another variable, they already are by virtue of having been selected. The GUI persists, and it's selections, persist until you change them or close it.
ASKER CERTIFIED SOLUTION
Kelly Garcia

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Kelly Garcia

ASKER
best solution
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23