Powershell 查找用戶的主SMTP地址
今天同事讓我生成一個(gè)報(bào)表,列出用戶的主SMTP地址后綴是@aus.ddb.com的用戶。
Get-ADUser可以直接獲取相關(guān)信息,不過(guò)主SMTP是隱藏在ProxyAddress這個(gè)屬性里面的,如果1個(gè)用戶有多個(gè)郵件地址,大寫(xiě)的SMTP的那個(gè)就是主地址。
腳本如下,獲取所有用戶的信息,然后創(chuàng)建一個(gè)空對(duì)象,對(duì)每一個(gè)對(duì)象的屬性進(jìn)行處理,把對(duì)應(yīng)的值放入對(duì)象, 最后過(guò)濾結(jié)果輸出。
$users = Get-ADUser -Filter {proxyAddresses -like '*'} -SearchBase "ou=sydney,dc=omnicom,dc=com,dc=au" -Properties proxyAddresses $pp=$null $pp=@{'name'=$null;'primarysmtp'=$null} $obj=New-Object -TypeName psobject -Property $pp $result=@() foreach($user in $users){ $primarySMTPAddress = "" foreach ($address in $user.proxyAddresses) { if (($address.Length -gt 5) -and ($address.SubString(0,5) -ceq 'SMTP:') ) { $primarySMTPAddress = $address.SubString(5) break } } $objtemp=$obj | select * $objtemp.name=$user.Name $objtemp.primarysmtp=$primarySMTPAddress $result+=$objtemp } $result | Where-Object{$_.primarysmtp -like "*aus.ddb.com*"} | sort Name
本文出自 “麻婆豆腐” 博客
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。