Skip to content

Instantly share code, notes, and snippets.

@YuukiNishikido
Last active April 25, 2021 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YuukiNishikido/22e12823665d18f31b6550cf9a88e4c5 to your computer and use it in GitHub Desktop.
Save YuukiNishikido/22e12823665d18f31b6550cf9a88e4c5 to your computer and use it in GitHub Desktop.
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