Z
Z
Z-RoVeR2018-09-17 16:49:08
PowerShell
Z-RoVeR, 2018-09-17 16:49:08

How to remove contacts from a specific OU by list from CSV?

There is a csv file with a list of obsolete contacts.
I try to delete on column Alias.
All that I could pick up myself:

Import-Module ActiveDirectory
Import-csv 'c:\tmp\del.csv' -Header 'Alias' | Foreach-Object { Remove-ADObject $_.Alias ​​-WhatIf }

But it didn't work out.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
azarij, 2018-09-17
@azarij

if you don't need to change column names when importing csv, then -header is not needed.
in what form is Alias ​​specified in csv (full name, distinguished name, object-guid, etc)?
You need to add the -identity key to remove-adobject and shove $_.alias into it.
and so issues objects from HELL?
Import-csv 'c:\tmp\del.csv' | Foreach-Object { Get-ADObject $_.Alias ​​}

S
Sergey, 2018-09-17
@LiS-31

Your pipeline is not built correctly:
If you read the get-help of the remove-ADObject command , you'll see that the remove-ADObject cmdlet gets the Identity parameter down the pipeline, and by value. those. before passing to foreach-object you need to turn usernames into objects.
Something like:
In the first part, you get the data from the file, then you get the AD objects of the contact class, with the specified parameter, and at the end you simply delete all the received objects.
The text is sketched roughly, it is not possible to check at the moment.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question