locked
Commands Run Individually, But Not As a Script. RRS feed

  • Question

  • Hello,

    To start with, the purpose of this script is to simplify the process of setting a user's automatic reply. This script will be ran locally on our Exchange 2013 server.

    When I run this script:

    ## Bypass the execution policy for the current session
    Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass
    
    ## Import the Exchange Snap-In
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
    
    ## Prompt the user to enter the desired auto reply and alias
    $alias = Read-Host -Prompt 'Please input the users alias'
    $msg = Read-Host -Prompt 'Please enter the desired auto reply'
    
    ## Sets the auto reply for the selected user
    Set-MailboxAutoReplyConfiguration $alias -AutoReplyState enabled -Externalaudience "All" -ExternalMessage $msg -InternalMessage $msg
    
    ## Confirmation message
    Write-Host "You have set the following automatic reply for '$alias': '$msg' "

    I receive this error:

    Set-MailboxAutoReplyConfiguration : A positional parameter cannot be found that accepts argument ''.
    At [INFORMATION REDACTED]\AutoReply v4.ps1:16 char:1
    + Set-MailboxAutoReplyConfiguration $alias -AutoReplyState enabled -Externalaudien ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Set-MailboxAutoReplyConfiguration], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Exchange.Management.StoreTasks.SetMailboxAutoReplyConfiguration

    I'm stumped at this point because if I type out each command and run them manually, it works without issues. But if I try to run the entire block of code, it errors out.



    • Edited by Mr.Salty Monday, June 25, 2018 4:52 PM
    Friday, June 22, 2018 9:30 PM

All replies

  • Remove the bad character as suggested in the error.

    \_(ツ)_/

    Friday, June 22, 2018 9:56 PM
  • Forgive me for being a PowerShell rookie, but what bad character?

    I've stared at my monitor for hours and cannot see the issue.

    Monday, June 25, 2018 4:55 PM
  • And now that you have changed the original question I can no longer see the bad character.


    \_(ツ)_/

    Monday, June 25, 2018 4:59 PM