查看完整版本: [-- win7连接到o365运行ps1脚本 出错 --]

Exchange技术论坛 -> Office 365 定制版用户讨论区 -> win7连接到o365运行ps1脚本 出错 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

ycguaa 2015-10-20 10:50

win7连接到o365运行ps1脚本 出错

我自己的系统为win7 sp1 64bit,通过powershell连接到office365之后,运行ps1脚本,提示下面错误,网上扒拉半天也没有什么效果,请大神们帮忙看看,哪里没有做。
[attachment=2786]


PS E:\ps> .\newuser.ps1
A parameter cannot be found that matches parameter name 'Properties'.
    + CategoryInfo          : InvalidArgument: (:) [Get-Mailbox],ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Get-Mailbox
    + PSComputerName        : partner.outlook.cn

ycguaa 2015-10-20 10:53
脚本内容如下


import-module ActiveDirectory

$csvPath = "NewEmployee.csv"
$ReadmePath = "WelcomeNewEmployees.zip"
$today=Get-Date
$yestoday=$today.AddDays(-1)

function send_email
{
#mail server configuration
$smtpServer = "smtpserver"
#$smtpUser = "username"
#$smtpPassword = "password"
#create the mail message
$mail = New-Object System.Net.Mail.MailMessage
#set the addresses
$MailAddress="mailaddress"
$mail.From = New-Object System.Net.Mail.MailAddress($MailAddress)

#set the content
$mail.Subject =  "给新员工的一封信"
$mail.Priority  = "High"
$mail.Body = $MailBody
$filename = $ReadmePath
$attachment = new-Object System.Net.Mail.Attachment($filename)
$mail.Attachments.Add($attachment)
#send the message
$smtp = New-Object System.Net.Mail.SmtpClient -argumentList $smtpServer
$smtp.Credentials = New-Object System.Net.NetworkCredential -argumentList $smtpUser,$smtpPassword
$mail.isBodyhtml = $true

$Contents = import-csv $csvPath
foreach ($Content in $Contents)
{
$MailtoAddress = $Content.Mail
$MailtoAddress
if ($MailtoAddress -ne "")
{
  #Get-Member -InputObject $mail.To
  $mail.To.Add($MailtoAddress)
  #echo $mail
  echo $MailtoAddress" mail is send..."
  $ctime=get-date
  $mail.To | select Address | foreach {$csend=-join($csend,$_.Address,";")}
  $log=-join ($ctime,"     ",$csend)
  echo $log >> .\log.txt
  $csend=""
  $smtp.Send($mail)
  $mail.To.Clear()
}
}

$mail.Attachments.remove($attachment)
}

Get-Mailbox -filter {Created -gt $yestoday} -Properties sAMAccountName,displayName,mail,employeeNumber,mobile,Created | select sAMAccountName,displayName,mail,employeeNumber,mobile,Created | export-csv -Encoding "Unicode"  -NoTypeInformation $csvPath

$NewEmployeeNumber = import-csv $csvPath | measure-object

$MailBody = "mailbody"

send_email


flowerwaiter 2015-10-22 18:01
ycguaa:脚本内容如下
import-module ActiveDirectory
.......?(2015-10-20 10:53)?

你把mobile去掉,把mail改成emailaddress试下。

Active Directory: Get-ADUser Default and Extended Properties
http://social.technet.microsoft.com/wiki/contents/articles/12037.active-directory-get-aduser-default-and-extended-properties.aspx

ycguaa 2015-11-16 10:54
flowerwaiter:你把mobile去掉,把mail改成emailaddress试下。
Active Directory: Get-ADUser Default and Extended Properties
http://social.technet.microsoft.com/wiki/contents/articles/12037.active-directory-get-aduser-default-and-extended-properties.aspx?(2015-10-22 18:01)?

版大,最后我找了台加入域的计算机操作,就没问题啦。


查看完整版本: [-- win7连接到o365运行ps1脚本 出错 --] [-- top --]



Powered by phpwind v8.7.1 Code ©2003-2011 phpwind
Time 0.019424 second(s),query:6 Gzip enabled