We help IT Professionals succeed at work.

store items in variable - Powershell

Kelly Garcia
Kelly Garcia asked
on
129 Views
Last Modified: 2017-04-18
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
Comment
Watch Question

Raheman M. AbdulMessaging and Directory Services
CERTIFIED EXPERT

Commented:
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 DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
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.
Senior Systems Administrator
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Kelly GarciaSenior Systems Administrator

Author

Commented:
best solution

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions