Hello,
i want to count the numbers of mailboxes stored in a exchange database.
When i try to show the output with a richtextbox i get an error.
# First i get the mailboxdatabse names
try
{
$DatenbankNamen = Get-MailboxDatabase | select Name
$rtb_log.Text += "`r`n Get-MailboxDatabase| Select Name `r`n"
$rtb_log.Text += $DatenbankNamen | Out-String
$rtb_Log.SelectionStart = $rtb_Log.TextLength;
$rtb_Log.ScrollToCaret()
$rtb_datenbanken.Text += $DatenbankNamen | out-string
$rtb_datenbanken.Text.SelectionStart = $rtb_datenbanken.Text.TextLength;
$rtb_datenbanken.Text.ScrollToCaret()
}
#then i want foreach Database count the mailboxes with measure-object and put the output to a richtextbox
# but the output dont work.
# how can i show the foreache result in a richtextbox ?
foreach ($dbnamen in $DatenbankNamen)
{
$datenbank = $dbnamen | Select-Object -ExpandProperty Name
$rtb_log.Text += "`r`n ..starte Abfrage auf Datenbank: " + $datenbank
$rtb_Log.SelectionStart = $rtb_Log.TextLength;
$rtb_Log.ScrollToCaret()
$anzahlPostfaecher = get-mailbox -database $datenbank -resultsize unlimited | Measure-Object
$rtb_log.Text += "`r`n get-mailbox -database " + $datenbank + " -resultsize unlimited | Measure-Object"
$rtb_log.Text += $anzahlPostfaecher | Out-String
$rtb_Log.SelectionStart = $rtb_Log.TextLength;
$rtb_Log.ScrollToCaret()
}
Foreach Loop Output to Richtextbox failed
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
-
- Posts: 2
- Last visit: Sun May 07, 2023 1:51 am
-
- Posts: 2
- Last visit: Sun May 07, 2023 1:51 am
Re: Foreach Loop Output to Richtextbox failed
i solved it like this:
$mailboxDBS = get-mailboxdatabase
foreach ($db in $mailboxDBS)
{
$count = (get-mailbox -database $db.name).count
$rtb_datenbanken.AppendText("Datenbank: " + $db.name + " Anzahl der Postfächer " + $count + "`n")
$rtb_datenbanken.SelectionStart = $rtb_Log.TextLength;
$rtb_Datenbanken.ScrollToCaret()
$rtb_log.Text += $count | Out-String
$rtb_Log.SelectionStart = $rtb_Log.TextLength;
$rtb_Log.ScrollToCaret()
}
$mailboxDBS = get-mailboxdatabase
foreach ($db in $mailboxDBS)
{
$count = (get-mailbox -database $db.name).count
$rtb_datenbanken.AppendText("Datenbank: " + $db.name + " Anzahl der Postfächer " + $count + "`n")
$rtb_datenbanken.SelectionStart = $rtb_Log.TextLength;
$rtb_Datenbanken.ScrollToCaret()
$rtb_log.Text += $count | Out-String
$rtb_Log.SelectionStart = $rtb_Log.TextLength;
$rtb_Log.ScrollToCaret()
}