首页 > 系统服务 > 详细

Powershell管理系列(二十五)PowerShell操作之或者AD账号及邮箱信息

时间:2015-11-15 19:16:18      阅读:616      评论:0      收藏:0      [点我收藏+]

-----提供AD\Exchange\Lync\Sharepoint\CRM\SC\O365等微软产品实施及外包,QQ:185426445.电话18666943750

有时候我们需要查询账号的很多属性,但是需要通过不同的命令去获取,有点类似SQL Server里面的多表连接查询,比如查询所有账号的ad账号描述,邮箱名,显示名,邮箱地址,邮箱数目,邮箱大小,存档邮箱大小,存档邮箱数目。

ad账号描述---对应AD账号的描述信息,通过Get-adUser 获取

邮箱名,显示名,邮箱地址---对应用户邮箱信息,通过get-mailbox获取

邮箱数目,邮箱大小---对应邮箱信息,通过命令get-mailbox |Get-MailboxStatistics 获取

存档邮箱大小,存档邮箱数目---对应存档邮箱信息,通过命令get-mailbox -Archive|Get-MailboxStatistics -Archive获取

这些属性通过SamAccountName这个共同的属性连接和查询,具体操作如下:


--------------------------------------------------------------------------------------------------------------------------------------------------

cls

Add-PSSnapin microsoft.exchange*

$mbxinfo=Get-mailbox -ResultSize unlimited |%{$_.SamAccountName}

$userlist = @() 

foreach ($i in $mbxinfo) 

$Description=Get-adUser $i -Properties * |%{$_.Description}

$user=get-mailbox $i

$userStatistics=get-mailbox $i |Get-MailboxStatistics

$userarchiveStatistics=get-mailbox $i -Archive|Get-MailboxStatistics -Archive

$userobject=New-object psobject 

$userobject | Add-Member -membertype noteproperty -Name AD账号描述      -value $Description

$userobject | Add-Member -membertype noteproperty -Name 邮箱名          -Value $user.Name

$userobject | Add-Member -membertype noteproperty -Name 显示名          -Value $user.DisplayName 

$userobject | Add-Member -membertype noteproperty -Name 邮箱地址        -Value $user.PrimarySmtpAddress

$userobject | Add-Member -membertype noteproperty -Name 邮箱数目        -Value $userStatistics.ItemCount

$userobject | Add-Member -membertype noteproperty -Name 邮箱大小        -Value $userStatistics.TotalItemSize

$userobject | Add-Member -membertype noteproperty -Name 存档邮箱数目    -Value $userarchiveStatistics.ItemCount

$userobject | Add-Member -membertype noteproperty -Name 存档邮箱大小    -Value $userarchiveStatistics.TotalItemSize

$userlist+=$userobject

$userlist

$userlist|export-csv -Path c:\userlist.csv -Encoding utf8 -NoTypeInformation

技术分享

本文出自 “周平的微软技术交流平台” 博客,请务必保留此出处http://yuntcloud.blog.51cto.com/1173839/1712918

Powershell管理系列(二十五)PowerShell操作之或者AD账号及邮箱信息

原文:http://yuntcloud.blog.51cto.com/1173839/1712918

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!