如何用powershell导出AD用户信息到CSV中并发送到本地邮箱中

如何用powershell导出AD用户信息到CSV中并发送到本地邮箱中

文中各个文件的命名可自己按需要更改,脚本基于powershell2.0

<#
Monthly AD User report
Writen by SanilInHighway 
Updated on 17/08/2015 prototype
Updated on 18/08/2015 details improve
Updated on 01/12/2015 add send email code
Updated on 18/05/2016 format date  output
Updated on 1/06/2015 update output of $PasswordExpirationDate & $PasswordLastSet
#>
$start = Get-Date
$array = @()
$DC='RAINBOW.domain.internal'
Clear-Content .\MonthReport_user.csv #清除原有数据
$AllUsers = get-aduser -Server $DC -Filter * #获取AD域中的所有用户
# $AllUsers = Get-Content .\UserID.txt
# $AllUsers = get-aduser -Server $DC -Filter * -Searchbase "OU=Support,OU=Accounts,OU=Customer,OU=Administration,DC=domain,DC=internal" #获取AD域指定OU目录下的用户
foreach ($user in $AllUsers ) {
    #获取用户所有属性,针对用户的各个属性进行筛选赋值,方便格式化输出到csv中
    $userinfo = Get-ADUser -Server $DC -Identity $user  -Properties *
    if ( $userinfo.Mail -eq $null){
  $mail = "No EA Email"}
        else{
  $mail =$userinfo.Mail }
    if($userinfo.Department -eq $null){
  $Department = "Not Provided"}
        else{
  $Department =$userinfo.Department}
    if($userinfo.Company -eq $null){
  $Company = 
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值