+ Post New Thread
Results 1 to 11 of 11
Windows Server 2008 R2 Thread, ems launch via command line with variable in Technical; Hi, I want to launch ems and do the following command: get-user %username% | set-mailbox -EmailAddressPolicyEnabled:$True %username% is variable that ...
  1. #1

    Join Date
    Jan 2010
    Posts
    64
    Thank Post
    7
    Thanked 5 Times in 5 Posts
    Rep Power
    10

    ems launch via command line with variable

    Hi,
    I want to launch ems and do the following command:

    get-user %username% | set-mailbox -EmailAddressPolicyEnabled:$True

    %username% is variable that will be passed into the command.

    Anyone have an idea?
    Thanks

  2. #2

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    Boston, MA
    Posts
    7,601
    Thank Post
    110
    Thanked 771 Times in 599 Posts
    Rep Power
    183
    You need to set your variable as $myVariable in PowerShell?

  3. #3

    Join Date
    Jan 2010
    Posts
    64
    Thank Post
    7
    Thanked 5 Times in 5 Posts
    Rep Power
    10
    ok, but i dont now how to run that command from a batch?

  4. #4

    Join Date
    Jan 2010
    Posts
    64
    Thank Post
    7
    Thanked 5 Times in 5 Posts
    Rep Power
    10
    just to clarify not done/used powershell before, but familair with vbs and bats...

  5. #5


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,792
    Thank Post
    262
    Thanked 2,964 Times in 2,179 Posts
    Rep Power
    846
    Could you clarify what you are trying to achieve with the command above? Even if you used $env:USERNAME (the PowerShell equivalent to %USERNAME%) I don't think that's what you need?

  6. #6

    Join Date
    Jan 2010
    Posts
    64
    Thank Post
    7
    Thanked 5 Times in 5 Posts
    Rep Power
    10
    ok, using this software: AD Infinitum Active Directory network administration multiple user manager tool for Windows 2000 and NT4

    but appears to be a bug where when creating exchange 2010 accounts it doesn't apply the default email policy. Once account is created I run the above command and it fixes this.

    speaking to developers, have the option to launch a separate program/batch after the account is created, and I can use the %username% variable from this program to pass it into the batch to run the command with the userid.

  7. #7


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,792
    Thank Post
    262
    Thanked 2,964 Times in 2,179 Posts
    Rep Power
    846
    This should do it...

    UpdatePolicy.cmd
    Code:
    @echo off
    cd /d "%~dp0"
    PowerShell -NoExit ".\UpdatePolicy.ps1" '%USERNAME%'
    UpdatePolicy.ps1
    Code:
    Param([string]$UserName)
    Set-Mailbox -Identity $UserName -EmailAddressPolicyEnabled:$true
    Put both scripts in the same folder and get AD Infinitum to run the batch file.

  8. #8

    Join Date
    Jan 2010
    Posts
    64
    Thank Post
    7
    Thanked 5 Times in 5 Posts
    Rep Power
    10
    Hi i'm getting

    The term 'Set-Mailbox' is not recognized as the name of a cmdlet, function, scr
    ipt file, or operable program. Check the spelling of the name, or if a path was
    included, verify that the path is correct and try again.
    Last edited by zbjsy; 2nd April 2012 at 04:28 PM.

  9. #9


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,792
    Thank Post
    262
    Thanked 2,964 Times in 2,179 Posts
    Rep Power
    846
    Forgot to mention that you either need to load the Exchange PowerShell snap-in or use Implicit Remoting to connect to your Exchange server in the .PS1 script above...

    www.mikepfeiffer.net/2010/02/managing-exchange-2010-with-remote-powershell/

    Which version of Exchange are you using and where are you running AD Infinitum from i.e a desktop PC or another server?

  10. #10

    Join Date
    Jan 2010
    Posts
    64
    Thank Post
    7
    Thanked 5 Times in 5 Posts
    Rep Power
    10
    exchange 2010, ad infit running on a win 2008 r2 server, has the exchange remote admin tools installed

  11. #11


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,792
    Thank Post
    262
    Thanked 2,964 Times in 2,179 Posts
    Rep Power
    846
    In that case, you should be able to do something like this...

    Code:
    Param([string]$UserName)
    
    $s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchange.example.net/PowerShell/ -Authentication Kerberos
    Import-PSSession $s
    
    Set-Mailbox -Identity $UserName -EmailAddressPolicyEnabled:$true
    or

    Code:
    Param([string]$UserName)
    
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
    . $env:ExchangeInstallPath\bin\RemoteExchange.ps1
    Connect-ExchangeServer -auto
    
    Set-Mailbox -Identity $UserName -EmailAddressPolicyEnabled:$true
    ^ change the bit in red though.

  12. Thanks to Arthur from:

    zbjsy (3rd April 2012)



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 3
    Last Post: 18th January 2011, 03:30 PM
  2. folder not visible except via command line
    By rocknrollstar in forum Windows
    Replies: 13
    Last Post: 13th June 2009, 09:24 PM
  3. Configuring Netgear WG302 via command line
    By randle in forum Hardware
    Replies: 8
    Last Post: 17th September 2008, 02:01 PM
  4. Command line installs? heeellllppp
    By contink in forum How do you do....it?
    Replies: 2
    Last Post: 2nd October 2006, 05:27 PM
  5. Command line tool for share permissions
    By NetworkGeezer in forum Windows
    Replies: 8
    Last Post: 19th June 2006, 07:32 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •