How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask ATLPROG Your Own Question
ATLPROG
ATLPROG, Computer Software Engineer
Category: Programming
Satisfied Customers: 7677
Experience:  MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
44910485
Type Your Programming Question Here...
ATLPROG is online now
A new question is answered every 9 seconds

Add-MailboxPermission breaks when using variables in

Customer Question

Add-MailboxPermission breaks when using variables in power-shell.
When adding variables to the above command it does not like it.
Set-ExecutionPolicy Unrestricted
. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'
Connect-ExchangeServer -auto
$username = Read-Host -Prompt 'User Account'
$EmailAddressOfUser=(Get-ADUser -Identity $UserName -Properties EmailAddress).EmailAddress
$MailboxDisplayName = Read-Host -Prompt 'Enter display name of user you are giving access to their mailbox'
$MailboxDelegateUsername = (Get-ADUser -Filter { Name -like $MailBoxDisplayName } -Properties samaccountname).samaccountname
$EmailAddressOfDelegate = (Get-ADUser -Identity $MailboxDelegateUsername -Properties EmailAddress).EmailAddress
Write-Host "You are giving $EmailAddressOfDelegate access to $EmailAddressOfUser's mailbox"
Add-MailboxPermission -Identity "$username" -User $EmailAddressOfDelegate -AccessRights Fullaccess -InheritanceType all
Submitted: 11 months ago.
Category: Programming
Expert:  Brent Woolverton replied 11 months ago.

Hello,

I am going to take a stab at this first, but it may to understand your environment that you are attempting to execute this within.

Are you operating Exchange 2010? As well, are you running this is as a stand alone or in an Exchange cluster farm? Lastly, are you executing this shell script from your administrator PC or from the console of the Exchange server?

I have made some modifications from what I have seen just taking an assumption that you are executing this on your local machine with Exchange tools added, and that you are operating an Exchange cluster farm within your forest. Please see the following modifications:

Add-MailboxPermission breaks when using variables in power-shell. When adding variables to the above command it does not like it.
Set-ExecutionPolicy Unrestricted
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
$env:ExchangeInstallPath\bin\RemoteExchange.ps1 Connect-ExchangeServer -auto
$username = Read-Host -Prompt 'User Account'

$EmailAddressOfUser=(Get-ADUser -Identity $UserName -Properties EmailAddress).EmailAddress $MailboxDisplayName = Read-Host -Prompt 'Enter display name of user you are giving access to their mailbox'

$MailboxDelegateUsername = (Get-ADUser -Filter { Name -like $MailBoxDisplayName } -Properties samaccountname).samaccountname
$EmailAddressOfDelegate = (Get-ADUser -Identity $MailboxDelegateUsername -Properties EmailAddress).EmailAddress Write-Host "You are giving $EmailAddressOfDelegate access to $EmailAddressOfUser's mailbox"
Add-MailboxPermission -Identity "$username" -User $EmailAddressOfDelegate -AccessRights Fullaccess -InheritanceType all

Related Programming Questions