切换到宽版
  • 1910阅读
  • 2回复

[求助]Get-ADUser找不到运行 AD Web 服务的默认服务器 [复制链接]

上一主题 下一主题
 

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



截图的错误内容为

PS E:\ps> .\newuser.ps1Get-ADUser : 找不到运行 Active Directory Web 服务的默认服务器
所在位置 E:\ps\newuser.ps1:56 字符: 1+ Get-ADUser -filter {Created -gt $today} -Properties sAMAccountName,displayName,m ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : ResourceUnavailable: (:) [Get-ADUser], ADServerDownException
    + FullyQualifiedErrorId : 找不到运行 Active Directory Web 服务的默认服务器。,Microsoft.ActiveDirectory.Management.Commands.GetADUser
我们一起妖怪。
分享到

只看该作者 1楼  发表于: 2015-10-20
Re:Get-ADUser找不到运行 AD Web 服务的默认服 ..
有没有大侠帮我解解呢?
我们一起妖怪。

只看该作者 2楼  发表于: 2015-10-20
Re:Get-ADUser找不到运行 AD Web 服务的默认服 ..
ps1内容如下


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-ADUser -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
我们一起妖怪。
快速回复
限60 字节
 
上一个 下一个