Showing posts with label get-mailbox. Show all posts
Showing posts with label get-mailbox. Show all posts

Tuesday, October 14, 2014

Everyday Powershell - Part 29 - Add-SMTPAlias

It's funny. When you think about how many clicks you need to go through to add an SMTP alias to an Exchange mailbox... There's a lot of clicks! Or you could just use this function and be done in 5 seconds.

function Add-SMTPAlias{
    <# Add-SMTPAlias
    .SYNOPSIS Adds smtp alias to a given mailbox

    .DESCRIPTION

    .PARAMETER alias
    Users Alias

    .PARAMETER
    newsmtpaddress desired email alias

    .EXAMPLE
    Add-IPToSMTPRelay -alias someuser -newsmtpaddress someusersotheremail@someserver.com 
    #>

    [CmdletBinding()]
    param (
        [Parameter(mandatory=$true,ValueFromPipeline=$true)]
        $alias,
        [Parameter(mandatory=$true,ValueFromPipeline=$true)]
        [mailaddress]$newsmtpaddress
    )
    process{
        $emailaddresses = (get-mailbox $alias).emailaddresses
        $emailaddresses += $newsmtpaddress.ToString()
        try{
            Set-Mailbox $alias -EmailAddresses $emailaddresses -ErrorAction stop
        }
        catch{
            write-warning ("Problem setting email address " + $_)
        }
    }
}

5 minutes or 5 seconds, the choice is yours GUI fans. Maybe it's time to give in to the power of the shell?

Wednesday, May 21, 2014

Everyday Powershell - Part 22 - Determine which mailboxes a user has fullaccess to

Had cause this week to figure out to which mailboxes a particular user had been assigned Full Access  permission.

Seemed a bit daunting, and would have taken us ages to audit just using the GUI. But it was actually very quick to get going in Powershell.
Add-PSSnapin *exchange*

$user = "TESTUSER"

$mailboxes = get-mailbox

foreach ($mailbox in $mailboxes)
{
    $mailboxpermission = Get-Mailboxpermission $mailbox
    foreach ($permission in $mailboxpermission)
    {
        $permission | where {$_.Accessrights -Contains "FullAccess" -and $_.user -like "*$user*"} | select Identity
    }
}

This was a cracking use of Powershell right in the nick of time and made us seem really professional to our big boss. Really can't recommend enough getting some powershell tools into your frequently used toolbelt.

Once you start using it, it's amazing the things you start to dream up. Things you wouldn't have even thought to do before learning the power of the shell!

Wednesday, May 14, 2014

Everyday Powershell - Part 21 - List Mailboxes with disabled user accounts

Any organisation will have users coming and going all the time. As admins we've got to manage much of this process. Running regular reports like this can catch errors in onboarding and offboarding processes.

Add-PSSnapin *exchange*
Get-Mailbox | Get-aduser -identity {$_.samaccountname} -Properties enabled | where {$_.enabled -eq $False} | Select Name

Very simple one liner script that'll list all mailboxes that have their associated users account disabled.

You could package this up into an email and send that to the relevant people on a regular basis.

Ahhh using Automation to make your team look more professional... Is there anything more rewarding?