jaenu22
jaenu22

Reputation: 1

Disable Computers with Powershell

I have a list of 150 computers I would like to disable in active directory with powershell.

So I have a csv file with the computernames and the follwoing script:

Import-Module ActiveDirectory

$computers = import-csv "C:\temp\test.csv"
foreach ($computer in $computers)
{
$computer | disable-adaccount
$computer | move-adobject -targetpath "OU=Disabled computers, DC=domain, DC=com"
}

Following error occures:

Disable-ADAccount : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeli
ne input.

Can someone please help?

Cheers

Upvotes: 0

Views: 17538

Answers (3)

R-X
R-X

Reputation: 1

I know this is an old post but I believe it's a type mismatch of Disable-ADAccount expecting a property rather than the whole object for input.

Using the example I added .DistinguishedName to the item passed to Disable-ADAccount and it worked. The input csv would need to have DistinguishedName available to the command though.

{
Disable-ADAccount $StaleComputer.DistinguishedName
Move-ADObject $StaleComputer.DistinguishedName -TargetPath "OU=Disabled Computers, DC=domain, DC=com"
}

Upvotes: 0

Ritesh
Ritesh

Reputation: 1

Create a txt file called disable.txt and put list of computers that u want to disable on C:\temp location

Run this script:

$Computer = Get-content c:\temp\disable.txt
Foreach ($Computer in $computers) {
    Set-ADComputer -Identity $computer -Enabled $false
}

Upvotes: 0

Hero Wanders
Hero Wanders

Reputation: 3292

Try a regular parameter instead of a pipe: disable-adaccount $computer (If necessary repeat this for the other call)

Also have a look at this question at Technet: Powershell script to disable AD account based on CSV file

Upvotes: 0

Related Questions