积极答复者
exchaneg ps脚本自动化的问题

问题
-
我用bat去调用EMS ps脚本实现自动化的执行,但是遇到一个问题,一些正常的ps脚本(不带参数即可执行的)可以正常的调用,但是我有一个脚本需要 .\xxx.ps1 -all带上-all参数才能执行,用bat调用时后我具体应该怎么写这个bat,以下是我目前的bat
powershell.exe -PSconsoleFile "c:\Program Files\Microsoft\Exchange Server\V14\Bin\exshell.psc1" -Command ".'d:\ps_bat\checksize.ps1'
这个bat中 路径的ps1脚本只要对即可,可以放到task里计划执行。这个bat我调用EMS的。 实现ps1的脚本自动化的任务有没有别的好的方法。
以上非常感谢Andes
答案
-
您好!
您可以参考以下链接中Running a Script from Cmd.exe主题中的命令及Create a Schedule Task试试。
PowerShell.exe -command ".’D:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; <path to your script>"
Scripting with the Exchange Management Shell
Schedule PowerShell Script for an Exchange Task
谢谢!
全部回复
-
具体我是用下面这个脚本来批量上传photo到AD中,让其自动在夜间执行。
param([Switch]$all, [String]$UserName)
#Default Values. Change them based on your environment.
$DefaultPhotoPath = '\\192.168.0.19\Photos'Function CheckPhoto(){
Write-Warning "Validating file(s).."
Write-Host "File exists... " -nonewline
If (Test-Path $PhotoPath)
{
Write-Host "[OK]" -ForeGroundColor Green
Write-host "Photo size... " -nonewline
$PhotoSize = Get-ChildItem $PhotoPath | select Length
If ($PhotoSize.Length -le 10000) { Write-Host "[OK]" -ForeGroundColor Green } Else { Write-Host "[Fail]" -ForeGroundColor Red; exit }
}
Else
{
Write-Host "[Fail]" -ForeGroundColor Red
Exit
}
}Function UploadAll(){
ForEach ($TempFile in Get-ChildItem $DefaultPhotoPath | Where-Object { $_.Extension -eq ".jpg" } )
{
$TempUserName = $TempFile.Name.substring(0, $TempFile.Name.Length - 4)
Write-Host $TempUserName -ForeGroundColor Yellow -NoNewLine
Import-RecipientDataProperty -Identity $TempUserName -Picture -FileData ([Byte[]]$(Get-Content -path $TempFile.Fullname -Encoding Byte -ReadCount 0))
Write-Host "[Done]" -ForeGroundColor Green
}
}If ( $all -eq $true)
{
Write-Warning " ## This action will upload all pictures of ."
Write-Warning " ## All pictures must have the same name of the usernames"
Write-Warning "Are you sure that you want upload all pictures to the users (Y/N)?"
UploadAll
}
Else
{
$PhotoPath = $DefaultPhotoPaty + $UserName + '.jpg'
CheckPhoto;
If ( $AbortMission -eq '$true' ) { Write-Error "Please, review the errors and try again." } Else { Import-RecipientDataProperty -Identity $UserName -Picture -FileData ([Byte[]]$(Get-Content -path $PhotoPath -Encoding Byte -ReadCount 0)) }
}Andes
-
您好!
您可以参考以下链接中Running a Script from Cmd.exe主题中的命令及Create a Schedule Task试试。
PowerShell.exe -command ".’D:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; <path to your script>"
Scripting with the Exchange Management Shell
Schedule PowerShell Script for an Exchange Task
谢谢!