Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
$password = Get-Content "pwd.dat" | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PsCredential "", $password
connect-msolservice -credential $msolcred
Get-MsolGroup -GroupType DistributionList -All | epcsv C:\MsolGroup.csv -Encoding default -NoTypeInformation
$Datapath = "C:\MsolGroupnew.csv"
$Datas = Import-Csv -Path $Datapath -Encoding Default
$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