Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Enable-Mailbox Script

$
0
0

Hi! 

I wrote a really simple script to enable mailboxes for active AD accounts that were created, (but for whatever reason, the mailbox was not.)  

Before: I would log into my exchange server, open Exchange Powershell and run the Enable-mailbox command.  
Example:  Enable-Mailbox -Identity "username" -Database "Database Name"
It would return the following:

Name                   Alias                ServerName       ProhibitSendQuota

----                      -----                  ----------               -----------------

Doe, Jane             jdoe               servername           unlimited

 

I then wrote the script listed below, as we were getting more requests to create mailboxes for user accounts and I wanted to avoid having to log into the server each time to enable mailboxes.

After:  The script I wrote is simple, but it is not returning the information above, but instead returning A LOT more details than needed.

RunspaceId  
Database                               
UseDatabaseRetentionDefaults          
RetainDeletedItemsUntilBackup          
DeliverToMailboxAndForward            
LitigationHoldEnabled               
SingleItemRecoveryEnabled       
RetentionHoldEnabled             
EndDateForRetentionHold    
StartDateForRetentionHold    
RetentionComment            
RetentionUrl                         
LitigationHoldDate             

etc...etc...etc...

When I run the script in Windows Powershell ISE, it displays the info correctly, but if I right click on the script and select "Run with Powershell", it displays the information that I do not want.  

Is there something I can add to the script or modify to show the results as:

Name                   Alias                ServerName       ProhibitSendQuota

----                      -----                  ----------               -----------------

Doe, Jane             jdoe               servername           unlimited

 

Script:

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://servername/PowerShell/ -Authentication Kerberos

Import-PSSession $Session

cls

Write-Host "============ Create mailbox for user ============" 

$UserName = Read-Host "Enter username "

$Database = Read-Host "Enter database "

Enable-Mailbox -Identity "$UserName" -Database "$Database"

Write-Host "============ Mailbox created ============" 

Read-Host -Prompt "Press Enter to exit" 

Thank you and any help is very much appreciated!!!


Viewing all articles
Browse latest Browse all 6937

Trending Articles