Link to home
Start Free TrialLog in
Avatar of Kelly Garcia
Kelly GarciaFlag 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
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

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

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
Avatar of Kelly Garcia
Kelly Garcia
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kelly Garcia

ASKER

best solution