Powershell to disable and move computers

I have a text file of computer names that are currently inactive on our domain.  I want a powershell script to read those names from the text file, disable them and move them to a designated Disabled Computers OU.  I found the following script:

$Computers = Get-Content -Path C:\temp\60.txt

ForEach ($Computer in $Computers)

{ $ADComputer = $null

$ADComputer = Get-ADComputer $Computer -Properties Description

If ($ADComputer)

{ Add-Content C:\temp\60.log -Value "Found $Computer, disabling and moved to Disabled Computers OU"

Set-ADComputer $ADComputer -Description "Computer Disabled on $(Get-Date)" -Enabled $false

Move-ADObject $ADcomputer -targetpath “OU=Disabled Computers,DC=mydomain,DC=com”



{ Add-Content C:\temp\60.log -Value "$Computer not in Active Directory"



The script is reading the text file okay.  I do not have the FQDN of the workstation, only its simple name (I'll use WS1 as an example).  Whenever I run the script it is coming back and telling me that WS1 is not in Active Directory but I know for a fact that it is.  I have tried changing the workstation name to FQDN, but still the same error message.  I have verified that there arent any spaces or carriage returns at the bottom of the list of the text file (in the script above, 60.txt).    What could i be missing or doing wrong?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Just in case, did you load ActiveDirectory module on powershell?

Import-module ActiveDirectory

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
BeachhausAuthor Commented:
I did not.  I have run PS Queryies from this server in the past so I didnt think it was necessary. Let me give it a try.
BeachhausAuthor Commented:
That was it, Gruppomg.  I didnt realize I had to do that.  Do I need to add that line before any PS script that will be accessing/modifying AD?
Yes, it's necessary.

There are other options, like save a profile in powershell to always load the module.

BeachhausAuthor Commented:
Thanks for the help.
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

From novice to tech pro — start learning today.