PoshCode Archive  Artifact [91beb39957]

Artifact 91beb39957918668f55cefb3f0c9b099a647bbc8022bd455971d85af744b9cf1:

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

# encoding: ascii
# api: powershell
# title: 
# description: Powershell script to get data from Exchange server
# version: 0.1
# license: CC0
# x-poshcode-id: 4113
# x-archived: 2013-05-09T16:33:35
#
#
$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 = "uuoresund.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 '*uuoresund.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