$variable = New-MoveRequest -Identity $m[$d] -TargetDatabase $TargetDatabase -WhatIf
Given that you're indexing into an array you might want to ensure the variable is positioned to capture output from the whole array (or that you use a collection you can add to). For example:# Before loop
$results = New-Object System.Collections.Generic.List[Object]
# Inside loop
$results.Add((New-MoveRequest -Identity $m[$d] -TargetDatabase $TargetDatabase -WhatIf))
# After loop
$control.Text = $results
And bear in mind that if you do get a result it'll almost certainly be some kind of object. A object with lots of properties won't necessarily display well in a text box (contingent on whatever the ToString method attached to each object does).
New-MoveRequest -Identity $m[$d] -TargetDatabase $TargetDatabase -WhatIf -ErrorVariable MoveError
if ($MoveError) {
$TextBox.Text = $MoveError.Exception.Message
}
At line:1 char:17
+ $OutputBox.Text $results
+ ~~~~~~~~
Unexpected token '$results' in expression or statement.
At :line:1 char:17
+ $OutputBox.Text $ <<<< results
$OutputBox.Text = $results
if ($a)
{
for ($d=0; $d -lt $a.length; $d++)
{
if (($AVS - $a[$d]) -gt 200)
{
$test = $AVS - $a[$d]
[System.Windows.MessageBox]::Show($test)
try {
$OutputBox.Text = New-MoveRequest -Identity $m[$d] -TargetDatabase $TargetDatabase -WhatIf *>&1
}
catch {
$OutputBox.Text = “Caught an exception:”
$OutputBox.Text = “Exception Type: $($_.Exception.GetType().FullName)”
$OutputBox.Text = “Exception Message: $($_.Exception.Message)”
}
}
}#for...
}#if ($a)
$OutputBox.Text += "`r`n"
$OutputBox.Text += New-MoveRequest -Identity $m[$d] -TargetDatabase $TargetDatabase -WhatIf *>&1
$OutputBox.Text + "`r`n"
The "$?" variable does hold a boolean that is supposed to show the result of the last command. However, this is a bit of a poor form of error control and it has little use beyond that.
You'll have to assign:
Open in new window