Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Скриптовые языки администрирования Windows (http://forum.oszone.net/forumdisplay.php?f=102)
-   -   [решено] Выполнение Exchange команд (http://forum.oszone.net/showthread.php?t=227854)

Ыть 14-02-2012 17:20 1858668

Выполнение Exchange команд
 
Доброго дня.
Есть сервер c Exchange 2010 SP2.
Нужно на нём выполнять скрипт: Test-Mailflow -TargetEmailAddress username@domain.name
Дело в том, что сам PS такую команду не знает. Её знает PS для Exchange 2010...
И я никак не пойму, что указывать в планировщике, что бы запустить скрипт именно в PS Exchange.
Спасибо.

Kazun 14-02-2012 17:32 1858680

Добавить в скрипт загрузку Snapin:

add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin

или подгрузить startup скрипт:

%programfiles%\Microsoft\Exchange Server\bin\Exchange.ps1

Ыть 14-02-2012 20:49 1858860

Kazun, извините, я не совсем понял.
вначале попробовал с самом ПС выполнить:

Цитата:

PS C:\> & 'C:\Program Files\Microsoft\Exchange Server\V14\Bin\Exchange.ps1'
The term 'Set-ADServerSettings' is not recognized as the name of a cmdlet, function, script 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.
At C:\Program Files\Microsoft\Exchange Server\V14\Bin\Exchange.ps1:48 char:21
+ Set-ADServerSettings <<<< -ViewEntireForest $false -WarningAction SilentlyContinue
+ CategoryInfo : ObjectNotFound: (Set-ADServerSettings:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Welcome to the Exchange Management Shell!

Full list of cmdlets: get-command
Only Exchange cmdlets: get-excommand
Cmdlets for a specific role: get-help -role *CAS* or *Mailbox*
Get general help: help
Get help for a cmdlet: help <cmdlet-name> or <cmdlet-name> -?
Show quick reference guide: quickref
Exchange team blog: get-exblog
Show full output for a cmd: <cmd> | format-list

Tip of the day #6:

Want to see the members of a dynamic distribution group that has a custom filter? Just use the Get-Recipient cmdlet. Typ
e:

$DDG = Get-DynamicDistributionGroup "Contoso Marketing Managers"
Get-Recipient -RecipientPreviewFilter $DDG.RecipientFilter
и всё равно:

Цитата:

PS C:\> Test-Mailflow -TargetEmailAddress username@domain.name
The term 'Test-Mailflow' is not recognized as the name of a cmdlet, function, script file, or operable program. Check t
he spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:14
+ Test-Mailflow <<<< -TargetEmailAddress username@domain.name
+ CategoryInfo : ObjectNotFound: (Test-Mailflow:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Kazun 14-02-2012 21:20 1858893

Код:

PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\V14\Bin\ExShell.psc1" -Command ". 'c:\scripts\Script.ps1'"

Ыть 14-02-2012 21:31 1858910

Kazun, Спасибо! только и этот скрипт не запускается, а открывает файл. прочитал про ExecutionPolicy
Код:

PS C:\Windows\system32> get-ExecutionPolicy
RemoteSigned

но всё равно локальный скрипт не запускает как надо...

Kazun 14-02-2012 22:16 1858941

Вывод скрипта:
Код:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
Test-Mailflow -TargetEmailAddress username@domain.name

Более подробно:
http://www.mikepfeiffer.net/2010/02/...shell-scripts/
http://www.mikepfeiffer.net/2010/02/...te-powershell/

Ыть 15-02-2012 20:07 1859638

Сделал так:
- в аргументах к команде C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe добавил:

Цитата:

-PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\V14\Bin\ExShell.psc1" -Command ". 'D:\script\mailflow.ps1'"
где в mailflow.ps1:
Цитата:

Test-Mailflow -TargetEmailAddress user.name@domain.name
собственно 4-ый пост, но без картинок из 6-го я не понял...


Время: 06:45.

Время: 06:45.
© OSzone.net 2001-