natalie.solero
Goto Top

Get deactivated computers in ad from csv list

article-picture
Hello guys,

i'm tryin to figure out which computers are deactivated in active directory. for that i provide the computer names in a csv list. i just want to output the computers which are deactivated. this is what i have. unfortunately i get all deactivated computers. but i only want that names provided in the csv.

Import-CSV -Path "C:\pc_names" | Select -expand Name | Get-ADComputer -searchbase 'XXX' -Filter {(Enabled -eq $False)} -Properties Name, OperatingSystem | Export-CSV “C:\DisabledComps.CSV” -NoTypeInformation  

Content-ID: 1128828179

Url: https://administrator.de/en/get-deactivated-computers-in-ad-from-csv-list-1128828179.html

Ausgedruckt am: 21.12.2024 um 13:12 Uhr

Xaero1982
Xaero1982 06.08.2021 aktualisiert um 11:16:11 Uhr
Goto Top
Hi,

if you only want the name:

Import-CSV -Path "C:\pc_names.csv" | Select -expand Name | Get-ADComputer -searchbase 'XXX' -Filter {(Enabled -eq $False)} | select Name | Export-CSV “C:\DisabledComps.CSV” -NoTypeInformation  

If you also want the OS

Import-CSV -Path "C:\pc_names.csv" | Select -expand Name | Get-ADComputer -searchbase 'XXX' -Filter {(Enabled -eq $False)} -Properties * | select Name, OperatingSystem  | Export-CSV “C:\DisabledComps.CSV” -NoTypeInformation  
natalie.solero
natalie.solero 06.08.2021 um 10:58:22 Uhr
Goto Top
Hi @Xaero1982, thank you for your reply. My Problem is, i don't want all pc names in the provided OU searchbase, i just want the names of the deactivated computers i have in the provided csv file
Xaero1982
Xaero1982 06.08.2021 um 11:03:13 Uhr
Goto Top
Sure i forgot the first import-csv. I will correct it
149062
149062 06.08.2021 aktualisiert um 11:11:24 Uhr
Goto Top
Import-CSV -Path "C:\pc_names.txt" -delimiter "," | Select -expand Name | Get-ADComputer -Properties Name, OperatingSystem | ?{!$_.Enabled} | Export-CSV "C:\DisabledComps.CSV" -NoTypeInformation  
natalie.solero
natalie.solero 06.08.2021 um 11:16:49 Uhr
Goto Top
at first the filter was missing. after I inserted this i still get all diabled pc names in the provided ou face-sad
Xaero1982
Xaero1982 06.08.2021 um 11:26:13 Uhr
Goto Top
I have created a pc_names.csv

name
pc1
pc2
pc3

PC1 is disabled.

I use this one
Import-CSV -Path "C:\pc_names.csv" | Select -expand Name | Get-ADComputer -searchbase 'XXX' -Filter {(Enabled -eq $False)} -Properties * | select Name, OperatingSystem  | Export-CSV “C:\DisabledComps.CSV” -NoTypeInformation  

and I got a file DisabledComps.csv with PC1 and Windows 10 Pro.

How does your importfile looks like? And whats the suffix of your file?
natalie.solero
natalie.solero 06.08.2021 aktualisiert um 15:22:40 Uhr
Goto Top
i have a normal csv file without the name header.

pc1
pc2
pc3

i tried your code with and without a header in my csv file.
if i add the name header, i get a csv with all pc names in it again and the following message. i work with a german system, so i don't exactly understand

Get-ADComputer : The input object cannot be bound to any parameters of the command because the command does not accept pipeline input or the input and its properties do not match any of the parameters that accept pipeline input.
In line:1 Character:61
149062
Lösung 149062 06.08.2021 aktualisiert um 11:53:46 Uhr
Goto Top
If you dont have a header in your file then you don't need import-csv and you can use Get-Content or you need to specify the -header Parameter with import-csv
Import-CSV -Path "C:\pc_names.txt" -Header 'Name' | Select -expand Name | Get-ADComputer -Properties Name, OperatingSystem | ?{!$_.Enabled} | Export-CSV "C:\DisabledComps.CSV" -NoTypeInformation  
or
Get-Content "C:\pc_names.txt" | Get-ADComputer -Properties Name, OperatingSystem | ?{!$_.Enabled} | Export-CSV "C:\DisabledComps.CSV" -NoTypeInformation  
natalie.solero
natalie.solero 06.08.2021 aktualisiert um 15:23:44 Uhr
Goto Top
Hi @149062,
when i run your code, i prompted to specify a filter. i used Enabled -eq $False. after that i get the exported csv with all deactivated pc's inside, not only with the provided names inside the .txt file -> your code example 2
after the code finished i get the following failure:

Get-ADComputer : The input object cannot be bound to any parameters of the command because the command does not accept pipeline input or the input and its properties do not match any of the parameters that accept pipeline input.
149062
149062 06.08.2021 aktualisiert um 12:22:48 Uhr
Goto Top
Zitat von @natalie.solero:

Hi @149062,
when i run your code, i prompted to specify a filter. i used Enabled -eq $False. after that i get the exported csv with all deactivated pc's inside, not only with the provided names inside the .txt file -> your code example 2
after the code finished i get the following failure

Get-ADComputer : Das Eingabeobjekt kann an keine Parameter des Befehls gebunden werden, da der Befehl keine Pipelineeingaben akzeptiert oder die Eingabe und deren Eigenschaften mit keinem der Parameter
übereinstimmen, die Pipelineeingaben akzeptieren.

No, runs here without problems if you use a current powershell version! When one ore more string arguments are transmitted via pipeline Get-ADComputer switches to another parameterset, and -Filter is not a member! So is works as designed face-wink.

If you don't tell us the real content of your text file we cannot help, because here it works as expected, when the textfile only contains the SamAccountNames of the computers.
natalie.solero
natalie.solero 06.08.2021 um 12:22:35 Uhr
Goto Top
i just have tried it with a csv file and a text file where i have just the computernames written in each row like
pc1
pc2
pc3
...
without header
149062
149062 06.08.2021, aktualisiert am 16.05.2023 um 14:41:15 Uhr
Goto Top
Quote from @natalie.solero:

i just have tried it with a csv file and a text file where i have just the computernames written in each row like
pc1
pc2
pc3
...
without header

As i said not a problem, have a look

screenshot

screenshot

screenshot

Works as designed!

I'm out.