切换到宽版
  • 5012阅读
  • 3回复

[求助]win7连接到o365运行ps1脚本 出错 [复制链接]

上一主题 下一主题
 

只看楼主 倒序阅读 0楼  发表于: 2015-10-20
我自己的系统为win7 sp1 64bit,通过powershell连接到office365之后,运行ps1脚本,提示下面错误,网上扒拉半天也没有什么效果,请大神们帮忙看看,哪里没有做。



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
我们一起妖怪哦。
分享到

只看该作者 1楼  发表于: 2015-10-20
脚本内容如下


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

我们一起妖怪哦。

只看该作者 2楼  发表于: 2015-10-22
回 ycguaa 的帖子
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
Exchange中文站10周年献礼。Exchange2016中文视频教程热销中:edu.exchangecn.com/course/12

只看该作者 3楼  发表于: 2015-11-16
回 flowerwaiter 的帖子
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)?

版大,最后我找了台加入域的计算机操作,就没问题啦。
我们一起妖怪哦。
快速回复
限60 字节
 
上一个 下一个