PoshCode Archive  Artifact [bf60c98289]

Artifact bf60c982890b2dcc2fb037a314a69fbbe52fb1a502fb1fb69b13496c888eb281:

  • File Set-Single-email.ps1 — part of check-in [81efb22da0] at 2018-06-10 12:58:04 on branch trunk — Script which creates a new Mail Enabled user with the Email address Policy disabled and a SINGLE custom email address attached to the account. Designed for new Powershell users. (user: Sean Kearney size: 3323)

# encoding: ascii
# api: powershell
# title: Set Single email 
# description: Script which creates a new Mail Enabled user with the Email address Policy disabled and a SINGLE custom email address attached to the account.  Designed for new Powershell users.
# version: 0.1
# type: script
# author: Sean Kearney
# license: CC0
# x-poshcode-id: 1521
# x-archived: 2015-07-18T04:02:05
# x-published: 2010-12-11T13:37:00
#
#
# Very simple script to use in Exchange 2007 with a dead simple task
# Create an email enabled user with the local Email Address Policy Disabled with a SINGLE email address
# Attached to it
#
# This can be used in an environment where you may have multiple email addresses but don't want an account picking
# up multiple email addresses or more explicitly where an email account should have only ONE address and it may not be the standard
# If you are hosting multiple domains on your server.  IE ABCCORPORATION.COM may have a private address for their website called
# @hotwebsitestuff.com.
#
# What this script will do after creating the address is purge all email addresses in the Proxy list and
# Replace it with just the one
#
# Questions and details just email sean@energizeit.ca
#
#
# Obtain FirstName, Last Name and designed email address
#
#
$FirstName=READ-HOST 'Enter First Name '
$LastName=READ-HOST 'Enter Last Name'
#
# Email address is in the form of name@domain.xxx and does not need to contain quotes or 'SMTP:'
#
$EmailAddress=READ-HOST 'E-mail Address reqd '
#
# Password for the account
#
$Password=READ-HOST 'DefaultPassword' -assecurestring
#
# Script will generate the needed fields from provided data.  Name is "FirstName Lastname"
# Alias is "Firstname.Lastname"
# Account will be created in a fictional OU in Active Directory "Contoso.Local" 
# With a default UPN of "firstname.lastname@contoso.local"
#
$Name=$FirstName+' '+$LastName
$Alias=$Firstname+'.'+$LastName
$OU='Contoso.local/Offices/Seattle'
$UPN=$Alias+'@contoso.local'
#
# Information will echo to the screen 
#
$FirstName
$LastName
$EmailAddress

$Password
$Name
$Alias
$OU
$UPN

#
# Create New Mailbox on Exchange 2007 server.   This is the standard New-Mailbox commandlet automatically generated by Exchange 2007
# With Hardcoded fields replaced by variables
#
New-Mailbox -Name $Name -Alias $Alias -OrganizationalUnit $OU -UserPrincipalName $UPN -SamAccountName $Firstname -FirstName $FirstName -Initials '' -LastName $Lastname -Password $Password -ResetPasswordOnNextLogon $false -Database 'OUREXCHANGESERVER\First Storage Group\Mailbox Database'
#
# If you find the mailbox doesn't appear immediately, you may have to do a "start-sleep 2" in Powershell V2 to make the script pause
# for two seconds
#
# Read the information about the mailbox in Quest and disable EmailAddressPolicy
#
get-mailbox $Alias | Set-Mailbox -EmailAddressPolicyEnabled $False
#
# Assign Mailbox Object to a variable "$MailboxUser"
# Using the "Clear()" Method purge the Property "EmailAddresses" within
#
$mailboxuser=get-mailbox $Alias
$mailboxuser.EmailAddresses.Clear()
#
# Add back in the ONE address you want
#
$mailboxuser.EmailAddresses.Add($EmailAddress)
#
# and then Set those changes back to the mailbox
#
$mailboxuser | set-mailbox