Hi there, I'm trying to write a custom sensor to return the Top 20 Mailboxes in Exchange 2010 ordered by Size however I'm not having much luck.
Here is the script:
#start new remote session from powershell $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://fmex1/PowerShell/ -Authentication Kerberos #import new session Import-PSSession $Session #Add-PsSnapin "Microsoft.Exchange.Management.PowerShell.E2010" -ErrorAction SilentlyContinue -WarningAction SilentlyContinue $servername=fmex1 $free=@{Label="Size(GB)"; Expression={$_.TotalItemSize.Value.ToGb()}} -First 20 | ft -auto $server=Get-Mailbox -Server $servername Get-MailboxDatabase -Status | select DisplayName,$free #PRTG Formatting Write-Host "<prtg>" foreach ($_.DisplayName in $server) { $Name=$_.DisplayName $Data=$_.TotalItemSize Write-Host "<result>" "<channel>$Name</channel>" "<value>$Data</value>" "</result>" } Write-Host "</prtg>" Exit 0 The text file that get written to the logs folder outputs: sensors\EXEXML\ExTop20.ps1:15 char:12 + foreach ($_.DisplayName in $server) { + ~ Missing 'in' after variable in foreach loop. At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\ExTop20.ps1:15 char:35 + foreach ($_.DisplayName in $server) { + ~ Unexpected token ')' in expression or statement. + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : MissingInInForeach
I don't understand because there is definitely an "in" in the foreach loop..
Any assistance would be fantaastic!
Add comment