zbjsy Posted April 2, 2012 Posted April 2, 2012 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
Ric_ Posted April 2, 2012 Posted April 2, 2012 You need to set your variable as $myVariable in PowerShell?
zbjsy Posted April 2, 2012 Author Posted April 2, 2012 ok, but i dont now how to run that command from a batch?
zbjsy Posted April 2, 2012 Author Posted April 2, 2012 just to clarify not done/used powershell before, but familair with vbs and bats...
Arthur Posted April 2, 2012 Posted April 2, 2012 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?
zbjsy Posted April 2, 2012 Author Posted April 2, 2012 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.
Arthur Posted April 2, 2012 Posted April 2, 2012 This should do it... UpdatePolicy.cmd @echo off cd /d "%~dp0" PowerShell -NoExit ".\UpdatePolicy.ps1" '%USERNAME%' UpdatePolicy.ps1 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.
zbjsy Posted April 2, 2012 Author Posted April 2, 2012 (edited) 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. Edited April 2, 2012 by zbjsy
Arthur Posted April 2, 2012 Posted April 2, 2012 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?
zbjsy Posted April 2, 2012 Author Posted April 2, 2012 exchange 2010, ad infit running on a win 2008 r2 server, has the exchange remote admin tools installed
Arthur Posted April 2, 2012 Posted April 2, 2012 In that case, you should be able to do something like this... Param([string]$UserName) $s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://[color="#FF0000"]exchange.example.net[/color]/PowerShell/ -Authentication Kerberos Import-PSSession $s Set-Mailbox -Identity $UserName -EmailAddressPolicyEnabled:$true or 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. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now