Over the last few months my colleague Jon has been providing me with some very useful Powershell snippets which I thought I’d share. A number of them require the Quest ActiveRoles Management Shell for Active Directory
Display Group memberships for a user.
(Get-QADUser username).MemberOf
Display the members of an Active Directory Group
Get-QADGroupMember "Groupname" | ft name,displayname -a
Bulk remove machine from Windows DNS
The text file contains a list on NetBios machine names.
gc computers.txt | %{dnscmd dnsservername /RecordDelete campus.ncl.ac.uk "$_" A}
Recuse through a Directory Structure and delete all file with a Creation date > 90 days.
The text file contains a list of UNC paths.
GC filecontainingpaths.txt | %{dir $_ -recurse | ?{!$_.psiscontainer -and $_.creationtime -lt ((get-date).adddays(-90))} | del -whatif}