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
Kelly GarciaSenior Systems AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
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

0
Chris DentPowerShell DeveloperCommented:
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.
0
Kelly GarciaSenior Systems AdministratorAuthor Commented:
This works well for me:

if ($null -ne $ListView.SelectedItems) {
        $ListView.ItemsSource = @($ListView.SelectedItems | Select-Object DisplayName, TotalItemSize, ItemCount, Database, TotalDeletedItemSize,DeletedItemCount, LastLoggedOnUserAccount, LastLogonTime, LastLogoffTime -OutVariable mailboxtomigrate)
		$global:m = $mailboxtomigrate.displayname
		[System.Windows.MessageBox]::Show('You have Selected Mailboxes: ' + $m)
		
    	}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kelly GarciaSenior Systems AdministratorAuthor Commented:
best solution
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.