Help with Powershell

Hello,

I need help with powershell script. I want to delete contact's (in domain a) but contact that are connected to AD blocked Accounts with email adresses (AD blocked Accounts in domain b).  Thanks for your help.

Martin.
Leos LeosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ben Personick (Previously QCubed)Lead Network EngineerCommented:
do you mean contacts or users who are disabled?

are you talking two office 365 instances?

afaik, blocking is only a thing in office 365, and isn't really about blocking email, it's about blocking credential sync, is that what you're trying to accomplish?

if not, then are you trying to get all of ths exchange spam blocking lists (its one per users mailbox) ganerate a single list off of those, and then use that to delete AD accounts in another domain that match those senders?
1
Leos LeosAuthor Commented:
I mean contact to Accounts that are blocked in other domain. About blocked account i mean account that are turn off. And this is not the Office 365.
0
Leos LeosAuthor Commented:
Sorry for my english. I try explain to you other way:

We have domain a - here are blocked accounts (turn off accounts)
we have domain b - here are contacts to accounts in domain a

Now. I need script to check account blocked in domain a, than check if this account have contact in domain b - if yes delete.

Thanks for help.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Ben Personick (Previously QCubed)Lead Network EngineerCommented:
find disabled user in domain A delete contacts with the same email address from domain B?
0
Leos LeosAuthor Commented:
Yes that's it.
0
Leos LeosAuthor Commented:
So you can help me with that?
0
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Hello Leos Leos, yes, I got quite sick this weekend and didn't post, even though I got on to do it, I just couldn't concentrate.

Here you are.

 On the source domain run this:

#Import-Module activedirectory
Import-Module activedirectory

# Put the path you want the CSV File to be in
$CSVFile = "C:\Admin\emails.csv"

#Get list iof disabled users which have email addresses:
$DisabledEmails=Get-ADUser -properties * -Filter '(emailaddress -ne $false) -and (enabled -eq $false)' | Select emailaddress

#Save list of disabled users to CSV to import into other domain.
$DisabledEmails | Export-CSV $CSVFile

Open in new window


Copy the CSV File to the destination domain where you want to remove the contacts and run the following code.

  As noted in the code below: Remove "-Whatif" to actually delete the contacts

#Import-Module activedirectory
Import-Module activedirectory

# Put the path you want the CSV File to be in
$CSVFile = "C:\Admin\emails.csv"

#Import listof disabled Users
$DisabledEmails2 = Import-CSV $CSVFile

#Get list of contacts whcih match the list of disabled users
$MatchedContacts = Get-ADObject -properties * -LDAPFilter "objectClass=Contact" | ? {$_.Mail -in $DisabledEMails2.emailaddress}

# Remove "-Whatif" to actually delete the contacts
$MatchedContacts | Remove-ADObject -confirm:$false -whatif

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Leos LeosAuthor Commented:
Thank you very much.
1
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Glad to help!  Once you have a chance please mark the comment as Accepted :)
0
PberSolutions ArchitectCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Ben Personick (Previously QCubed) (https:#a42365835)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Pber
Experts-Exchange Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.