Get deactivated computers in ad from csv list
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.
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
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
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
12 Kommentare
Neuester Kommentar
Hi,
if you only want the name:
If you also want the OS
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
Import-CSV -Path "C:\pc_names.txt" -delimiter "," | Select -expand Name | Get-ADComputer -Properties Name, OperatingSystem | ?{!$_.Enabled} | Export-CSV "C:\DisabledComps.CSV" -NoTypeInformation
I have created a pc_names.csv
PC1 is disabled.
I use this one
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?
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?
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
or
Import-CSV -Path "C:\pc_names.txt" -Header 'Name' | Select -expand Name | Get-ADComputer -Properties Name, OperatingSystem | ?{!$_.Enabled} | Export-CSV "C:\DisabledComps.CSV" -NoTypeInformation
Get-Content "C:\pc_names.txt" | Get-ADComputer -Properties Name, OperatingSystem | ?{!$_.Enabled} | Export-CSV "C:\DisabledComps.CSV" -NoTypeInformation
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.
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 .
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.
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
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
Works as designed!
I'm out.