Powershell and Exchange server 2007 - multiple commands
Hi to all
I need to use PS to automate some tasks:
get-mailbox -identity mail.test | Set-Mailbox -AcceptMessagesOnlyFrom
postmaster@TEST.group -HiddenFromAddressListsEnabled $true
get-mailbox -identity mail.test | Move-Mailbox -TargetDatabase SERVER\sgd\dbd -silent
get-mailbox -identity mail.test | move-QADObject -NewParentContainer TEST.group/disabled account'
disable-qaduser -identity mail.test
The problem is I have to find a way to launch them all togheter, not one by one, even providing multiple users. Currently I'm not able to launch a complex cmdlet because Ps accept just one command after a pipeline, and multiple pipelines are not working
Can you help me?
thank you very much
MCT MCSE:M|S MCITP MCTS
May 24th, 2010 5:31pm
hi,
Save all your commands to a file and save it as .ps1 file, say Test1.ps1.
Then you can run the commands in this file in 2 ways. [all commands will run one by one]
1. Copy this file to "Scripts" folder in the exchange installation folder and then open EMS and just enter the name of .ps1 file, say Test1.ps1 and press enter.
OR
2. open EMS and goto the folder where u saved your .ps1 file [like cd "yourFolderPath"] and then just enter the name of .ps1 file, say Test1.ps1 and press enter.
Hope this help u.
Regards,Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM)
www.HostingController.com
Free Windows Admin Tool Kit Click here and download it now
May 24th, 2010 7:21pm
As Laeeq mentioned, you can add these commands to a PowerShell script.
http://technet.microsoft.com/en-us/library/ee176949.aspx
Santhosh Sivarajan | MCTS, MCSE (W2K3/W2K/NT4), MCSA (W2K3/W2K/MSG), CCNA, Network+ Houston, TX http://blogs.sivarajan.com/ http://publications.sivarajan.com/ This posting is provided "AS IS" with no warranties, and confers no rights.
May 24th, 2010 11:04pm
thanks for replies, but actually what I need is to do the various operations on a
get-mailbox output. I need to perform them on all my disabled users, so for example:
get-qaduser -disabled| Set-Mailbox -AcceptMessagesOnlyFrom postmaster@TEST.group -HiddenFromAddressListsEnabled $true
get-qaduser -disabled | Move-Mailbox -TargetDatabase SERVER\sgd\dbd -silent
get-qaduser -disabled | move-QADObject -NewParentContainer TEST.group/disabled account'
get-qaduser -disabled | disable-qaduser
I would life to find a way to get one imput (get-qaduser) on several commandsMCT MCSE:M|S MCITP MCTS
Free Windows Admin Tool Kit Click here and download it now
May 25th, 2010 6:02pm
Yes,
U can do like this:
get-qaduser -disabled | forEach{
Set-Mailbox $_.Identity -AcceptMessagesOnlyFrom postmaster@TEST.group -HiddenFromAddressListsEnabled $true
Move-Mailbox $_.Identity -TargetDatabase SERVER\sgd\dbd -silent
move-QADObject $_.Identity -NewParentContainer TEST.group/disabled account'
disable-qaduser $_.Identity
}
so basically the get-qaduser will give you all objects one by on in foreach loop, and at one iteration u can call many operations on that user using any of the allowed attributes in the Exchange/Quest commands, like $_.Identity.
Regards,
Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM)
www.HostingController.com
May 25th, 2010 6:10pm
Try to use variables:
$users = get-mailbox -server <<server>> -resultsize unlimited
Then you have your users in the $users variable. You can work with them in a foreach loop:
foreach ($user in $users)
{
Set-Mailbox -id $user -AcceptMessagesOnlyFrom
postmaster@TEST.group -HiddenFromAddressListsEnabled $true
...
}
Free Windows Admin Tool Kit Click here and download it now
May 25th, 2010 6:11pm
trying but still not working. will continue tio try and post more usefull infoMCT MCSE:M|S MCITP MCTS
May 26th, 2010 4:15pm
trying but still not working. will continue tio try and post more usefull info
MCT MCSE:M|S MCITP MCTS
If u are having some errors then post the collection of commands u used and the error details.
Regards,Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM)
www.HostingController.com
Free Windows Admin Tool Kit Click here and download it now
May 26th, 2010 4:46pm
at the end I found a solution based on a simple point: -identity provided by get-qaduser is different from the one required by set-mailbox and other exchange cmdlet. Here the working script
note the use of $user.dn as identity argument
$users =get-qaduser
-includeallproperties
-sizelimit 10
-Disabled
foreach ($user
in
$users)
{
Set-Mailbox
-id
$user.dn
-AcceptMessagesOnlyFrom
postmaster@TEST.com
-HiddenFromAddressListsEnabled
$true
Move-Mailbox
-id
$user.dn
-TargetDatabase
SERVER\sgd\dbd
move-QADObject
-id
$user.dn
-NewParentContainer
TEST.com/disabled account'
}
MCT MCSE:M|S MCITP MCTS
June 10th, 2010 12:42pm