Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AzureADメールエイリアス抽出
#予め作成した認証情報を取り込み
$password = Get-Content "pwd.dat" | ConvertTo-SecureString
#認証情報を変数に取り込んで認証
$credential = New-Object System.Management.Automation.PsCredential "xxx@xxx.co.jp", $password
$msolcred=$credential
#O365に接続
connect-msolservice -credential $msolcred
#エイリアス情報を全件取得し、ローカルにCsv出力した上で配列変数に取り込み
Get-MsolGroup -GroupType DistributionList -All | epcsv C:\MsolGroup.csv -Encoding default -NoTypeInformation
$Datapath = "C:\MsolGroupnew.csv"
$Datas = Import-Csv -Path $Datapath -Encoding Default
#hogehoge@が含まれているエイリアスを抽出し、Csv出力
$Count = 0
[string[]]$Hogehits = @("targetAddress")
ForEach($Data in $Datas){
$checkmember = Get-MsolGroupMember -All -GroupObjectid $Datas[$Count].ObjectId
If($checkmember.EmailAddress -Like "hogehoge@*"){
$Hogehits += $Datas[$Count].EmailAddress
}
$Count = $Count + 1
}
$Hogehits > c:\hogehoge@_list.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment