Clean WDS Prestaged Computers

Good Day,

I need a script to clean my WDS server prestage device information.  We have over 600 computers that have no Referral server listed.  I would like to remove all the prestaging information from them.

I am a novice at scripting.

When I run the following command:
WDSUTIL / Verbose /Get-ALLDevices /Forest:Yes

It displays all the information for all the prestaged machines.

When I run this command:
WDSUTIL / Verbose /Get-ALLDevices /Forest:Yes /ReferralServer:
(we have multiple referral servers and this displays all systems with the referral server defined)

It displays all the information for computers that have any referral server defined.

I would like to only keep the prestaging information for computers that have a referralserver defined.

Any help is appreciated.
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.

Leon TaljaardSystem Center Specialist - ArchitectureCommented:
Hey there,

Are these ones without the "referralServer" perhaps rejected ones ?

Maybe have a look at this

Purging WDS database and clearing prestaging values from AD computers

Do you get anything when using this command

WDSUTIL /Delete-AutoAddDevices /DeviceType:RejectedDevices

Open in new window

mrfiteAuthor Commented:
Sorry for any confusion,

All the computers were approved through an Active Directory script.  None were rejected.

When I ran the script you provided it returned no matching devices.
Leon TaljaardSystem Center Specialist - ArchitectureCommented:
Oh ok no problem, have you perhaps had a look at the link provided ?

You are probably going to need to either remove these devices from AD or perhaps flush the entire WDS database and re-auth all PC's again. But i would be careful in doing that first.

I have never needed to try remove machines that had no server defined
mrfiteAuthor Commented:
After a few days of searching I figured out the variable I was missing.  netbootMachineFilePath defines the referral server.  

Below is the powershell script that will clean up Windows Deployment Services (WDS) when you have prestaged machines with no referral server.

Get-ADComputer -Filter {NetbootGUID -like "*"} -Properties NetbootGUID,created,OBJECTGUID,name,netbootMachineFilePath | ? {$_.netbootMachineFilePath -eq $null} | Set-ADComputer -clear NetbootGUID

Open in new window

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
mrfiteAuthor Commented:
This solution does exactly what it should do.
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
Shell Scripting

From novice to tech pro — start learning today.