Can logical AND be used in a Get-ADComputer statement?
I can get all the computer names and IP addresses with the following after I Import-Module ActiveDirectory with the following code I found elsewhere during a search:
`Get-ADComputer -Filter (OperatingSystem Like “Windows 7*” | Format-Table IPv4Address, Name -Wrap -Auto`
Is there a way to include logical AND in the statement so that I get the Windows 7 computers along with CanonicalName includes the string ABCD? Let’s say some of the Computers are at site ABCD and some are at site EFGH. I only want to pull the ABCD site computers that are Windows 7.
If you get into really complex criteria, it can be easier to use the -ldapFilter parameter and the LDAP filtering syntax. It’s a lot more robust than what -Filter can parse. Essentially, -Filter has to be translated to LDAP so it’s the translation code that creates the limitations. With -ldapFilter, you can do whatever.
Hey guys. Thanks for the tips. I am not sure if I am over complicating this or not. I am still having trouble getting a specific subnet pulled from Active Directory. If I have the 10.5.100, 10.6.100, and 10.7.100 subnets for my Windows 7 Computers and I want to pull out only the 10.5.100 then how is that done. In my googling I did see some syntax using a -where option, but I’ve yet to get it to work.
Here is what I have so far that look good on the screen output:
In the above code is where I’ve tried to use the “-where” syntax, to no avail, to grab ONLY the 10.5.100 subnet, for example. I’m throwing in OS and Name, just to prove on the screen that I am indeed getting only Windows 7 systems. My ultimate goal it to produce a list of IP addresses only that are Windows 7 computers.
Craig … I’ll start looking at searchbase examples.
I seem to take one step forward and two backwards. So I run the above Get-ADComputer syntax and it works. I then assign it to a variable to get IP addresses i.e.:
I can then echo $Win7Computers and the list looks good. But when I try to run it through a foreach:
foreach ($ip in $Win7Systems) {
ping $ip
other stuff
}
and I get output such as PIng request could not find host Microsoft.PowerShell.Commands. etc. Is not the $Win7Systems putting the IP list in some sort of Array?