Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Active Directory with PowerShell

You're reading from   Active Directory with PowerShell Learn to configure and manage Active Directory using PowerShell in an efficient and smart way

Arrow left icon
Product type Paperback
Published in Jan 2015
Publisher Packt
ISBN-13 9781782175995
Length 230 pages
Edition 1st Edition
Concepts
Arrow right icon
Authors (2):
Arrow left icon
YELLAPRAGADA U PADMAVATHI YELLAPRAGADA U PADMAVATHI
Author Profile Icon YELLAPRAGADA U PADMAVATHI
YELLAPRAGADA U PADMAVATHI
Pamarthi Venkata Sitaram Pamarthi Venkata Sitaram
Author Profile Icon Pamarthi Venkata Sitaram
Pamarthi Venkata Sitaram
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Let's Get Started 2. Managing User and Computer Objects FREE CHAPTER 3. Working with Active Directory Groups and Memberships 4. Configuring Group Policies 5. Managing Domains, Organizational Units, Sites, and Subnets 6. Advanced AD Operations Using PowerShell 7. Managing DFS-N and DFS-R Using PowerShell 8. Managing Active Directory DNS Using PowerShell 9. Miscellaneous Scripts and Resources for Further Learning Index

Deleting computer accounts

As discussed in the previous section, as a system administrator one must adhere to the security policies of the organization and keep their Active Directory database clean and tidy. As part of this process, you might want to delete stale/offline computer objects from Active Directory.

Use the following simple command to delete a computer account:

Remove-ADComputer -Identity COMP1

The most common use case is searching for computers older than x days and removing them. You can achieve this using the following command:

$Computers = Get-ADComputer -Filter * -Properties LastLogonDate | ?  {$_.LastLogonDate -lt (get-date).Adddays(-10) }
$Computers | Remove-ADComputer

Tip

You need to be very careful while performing the delete operation. Any mistake in the filters can result in your production computers being deleted. So, I prefer storing the Get-ADComputer cmdlet results in a variable ($computer in this example), reviewing the list, and then passing it to the Remove-ADComputer...

You have been reading a chapter from
Active Directory with PowerShell
Published in: Jan 2015
Publisher: Packt
ISBN-13: 9781782175995
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image