Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
Active Directory
Search AD for certain servers
Last Post 09 Dec 2009 07:24 AM by
mks
. 2 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
mks
New Member
Posts:2
08 Dec 2009 12:32 PM
I new to powershell and trying to learn. I have a script that is not working right. I want to be able to search the entire AD domain for servers that start with MC. I have an OU called servers and under that OU are other containers and they all have servers in them. Some of the servers start with MC and I want to search for all of them. The script below only seems to show me a few servers but not all of them. Is there a problem with the script?
$dom = [System.DirectoryServices.ActiveDirectory.domain]::GetCurrentdomain()
$root = [ADSI] "GC://$($dom.Name)"
$searcher = New-Object System.DirectoryServices.DirectorySearcher($root, "(objectCategory=computer)")
$searcher.FindAll() | where { $($_.Properties.cn).StartsWith('mc') } | % { $_.Properties.name }
Thanks for the help.
Karl Mitschke
Basic Member
Posts:451
08 Dec 2009 12:39 PM
Hi;
i'd do my search like this:
$dom = [System.DirectoryServices.ActiveDirectory.domain]::GetCurrentdomain()
$root = [ADSI] "GC://$($dom.Name)"
$searcher = New-Object System.DirectoryServices.DirectorySearcher($root, "(&(objectCategory=computer)(name=wc*))")
$searcher.FindAll()
Karl
http://unlockpowershell.wordpress.com
Co-Author, Windows PowerShell 2.0 Bible
-join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
mks
New Member
Posts:2
09 Dec 2009 07:24 AM
Thanks Karl. Being new to scripting and PS it is a big help. Now that is working I need to loop through the servers and delete some folders. Would you have some code I could look at that does something like this? Thanks for your help.
You are not authorized to post a reply.
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
Active Directory
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2