Ad Widget

Collapse

Using a Powershell script to check on Exchange Online mailboxes size

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ineedhealing
    Junior Member
    • Oct 2021
    • 3

    #1

    Using a Powershell script to check on Exchange Online mailboxes size

    Hello everyone,

    I have recently set up a zabbix server 5.4 with around 200 hosts and 15k checks on a Ubuntu Server 20.04 LTS VM for the infrastructure at the company I currently work at, using a lot of community templates and reading through a lot of these forums, but unfortunately I could not find any for Exchange Online or other M365 services.

    Let me start this by saying I have zero background in scripting/coding, other than a little bit of powershell so please share some of your wisdom with me.

    I have found and modified a powershell script that lists mailboxes above a certain size, and a variation of that that just counts how many there are (so I can create the appropriate zabbix trigger easier).
    Of course, powershell has been installed on the Ubuntu server, together with the necessary modules (ExchangeOnlineManagement & PSWSMan). The script has two parts, it first uses Connect-ExchangeOnline to connect and then Get-EXOMailbox to get the list of mailboxes after filtering out the smaller ones.
    The ps1 script works fine on both the Ubuntu VM and on my Windows PC.

    I then researched some more and saw that I have to create a bash .sh script to call that .ps1 powershell script and create an external check with the .sh script's name in zabbix web.
    After configuring all that, I am stuck as in the history log of the external check item I can see that it cannot identify the powershell modules I mentioned in order to connect to the Exchange Online. When I put the Import-Module in the .ps1 script and re-tried, it says it cannot find any such modules to import...

    both .ps1 and .sh scripts have been chmod'ed with +x and -R 777.


    History log:

    The term 'Connect-ExchangeOnline' is not recognized as a name [96m | [91mof a cmdlet, function, script file, or executable program. [96m | [91mCheck the spelling of the name, or if a path was included, [96m | [91mverify that the path is correct and try again.

    and after adding import-module in the script:
    The specified module 'ExchangeOnlineManagement' was not loaded [96m | [91mbecause no valid module file was found in any module directory.

    You have my gratitude in advance.
  • ineedhealing
    Junior Member
    • Oct 2021
    • 3

    #2
    This might have something to do with the zabbix user not having access to these modules, is it possible to run the scripts as another user, or to login via the zabbix user to the VM? I tried to go from my local admin to zabbix and it gives me authentication error, and if I login with root and try to su to zabbix, it says this account is currently not available.

    Thanks!

    Comment

    Working...