PoshCode Archive  Artifact [a2af73f8e0]

Artifact a2af73f8e05c644552e138a6b7e8069b0f74534a023e7c3d410ecf8504408193:

  • File Powershell-script-to-get-data-.ps1 — part of check-in [ccc7c90938] at 2018-06-10 13:36:45 on branch trunk — Powershell script to get data from Exchange server (user: unknown size: 1455)

# encoding: ascii
# api: powershell
# title: 
# description: Powershell script to get data from Exchange server
# version: 0.1
# license: CC0
# x-poshcode-id: 4112
# x-archived: 2013-05-09T15:20:55
#
#
$WarningPreference = "SilentlyContinue"
$password = Get-Content C:\securestring.txt | convertto-securestring
$username = "PROD\administrator"
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password

$uucenter = "uu-lillebaelt.dk"
$totalSize = 0

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://prod-exch1.prod.local/PowerShell/ -Credential $credentials
Import-PSSession $session -DisableNameChecking | out-null

foreach ($mbx in Get-Mailbox) 
{
    if($mbx.PrimarySMTPAddress -like '*uu-lillebaelt.dk*')
    {
        $size = (Get-MailboxStatistics $mbx.Identity).TotalItemSize

        $position = $size.IndexOf("(")
        $size = $size.Substring($position+1)

        $position = $size.IndexOf(" ")
        $size = $size.Substring(0, $position)

        $totalSize = [long]$totalSize + [long]$size
    }
}

$totalSize = $totalSize/1000000

Write-Host "<prtg>"
Write-Host "    <result>"
Write-Host "        <channel>$uucenter</channel>"
Write-Host "        <value>$totalSize</value>"
Write-Host "        <float>1</float>"
Write-Host "    </result>"
Write-Host "</prtg>"

Remove-PSSession $session

Exit 0