2016-05-17 13 views
0

Meine Powershell-Skript-Funktion:AppendText Methode funktioniert nicht

function Click { 
    $outputBox = New-Object System.Windows.Forms.TextBox 
    $outputBox.Location = New-Object System.Drawing.Size(10,150) 
    $outputBox.Size = New-Object System.Drawing.Size(565,200) 
    $outputBox.MultiLine = $True 
    $outputBox.ScrollBars = "Vertical" 
    $Form.Controls.Add($outputBox) 

    $userid = $Emailid.text; 
    $uid=[bool]($userid -as [Net.Mail.MailAddress]) 
    if($uid -eq "True") 
    { 
     $outputBox.Text = "Email id exists" 
    } 
    else 
    { 
     $outputBox.Text = "Email id not exists" 
    } 
    $owa = [bool](Get-CasMailbox $userid | fl owaenabled) 
    if($owa -eq "True") 
    { 
     $outputBox.AppendText = " your email id has owa access" 
    } 
    else 
    { 
     $outputBox.AppendText = "sorry... your email id has not owa access" 
    } 
} 

Wenn meine Taste oben Funktion gedrückt wird, aufgerufen wird, aber ich bin nur in der Lage letztes Ergebnis in die $outputBox zu sehen, aber ich mag sowohl die Ausgabe in Textfeld. Auch ForegroundColor funktioniert nicht damit. Es gibt Fehler, also wie man ForegroundColor damit benutzt?

+0

Haben Sie jeden Text wie $ outputBox.Text + = "YOUR TEXT' n" –

+0

anhängen möchten Wenn Sie zwei Strings verketten möchten, verwenden Sie' + = 'statt einen neuen Wert mit' = Zuweisung ' . –

+0

Ich habe Ihren Vorschlag versucht, aber zweiter Text kommt nicht in neue Zeile und auch Vordergrundfarbe funktioniert nicht damit – jasmin

Antwort

1

AppendText() ist eine Methode. Sie verwenden es wie eine Eigenschaft. Ändern Sie dies:

if($owa -eq "True") 
{ 
    $outputBox.AppendText = " your email id has owa access" 
} 
else 
{ 
    $outputBox.AppendText = "sorry... your email id has not owa access" 
} 

in diese:

if($owa -eq "True") 
{ 
    $outputBox.AppendText(" your email id has owa access") 
} 
else 
{ 
    $outputBox.AppendText("sorry... your email id has not owa access") 
} 

Wie für die Vordergrundfarbe: Sie setzen nicht, dass überall, und die Eigenschaft wird ForeColor genannt, nicht ForegroundColor.

$outputBox.ForeColor = 'Red'