Link to home
Start Free TrialLog in
Avatar of Kelly Garcia
Kelly GarciaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Convert Variable to Array

HI All,

I have this variable in my powershell script:

$global:m = $mailboxtomigrate.displayname

Open in new window


I then have this code that I run to execute migration of mailboxes:

$a=$mailboxtomigrate.totalitemsize | select @{label='Size' ; expression={ ($_.split('(')[1].split(' ')[0].replace(',',''))/1024/1024/1024 }} | select-object -expand Size



for ($d=0; $d -lt $a.length; $d++) {
New-MoveRequest -Identity $m[$d] -TargetDatabase $TargetDatabase -WhatIf 
}

Open in new window


problem is when there is only one item in $m the new-moverequest fails.

I therefore believe I need to convert the $m to an array, how do I do this?
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
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

Fantastic! just testing the code, I am sure it will work!
The code works, but the results are not displaying:

$OutputBox.Text += New-MoveRequest -Identity $m[$d] -TargetDatabase $TargetDatabase -WhatIf *>&1
$OutputBox.Text += "`r`n"

Open in new window


instead the results are displaying on the powershell screen
You'll still get the WhatIf text on the screen. Can't redirect that one.