# Get-AdComputer and multiple -Searchbase parameters

**URL:** <https://forums.powershell.org/t/get-adcomputer-and-multiple-searchbase-parameters/3548>\
**Category:** PowerShell Help\
**Created:** [December 18, 2014, 8:41pm UTC](https://forums.powershell.org/t/get-adcomputer-and-multiple-searchbase-parameters/3548 "2014-12-18T20:41:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bytejunkie](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/bytejunkie/32/813_2.png) [@bytejunkie](https://forums.powershell.org/u/bytejunkie)\
**Post date:** [December 18, 2014, 8:41pm UTC](https://forums.powershell.org/t/get-adcomputer-and-multiple-searchbase-parameters/3548/1 "2014-12-18T20:41:38Z")

</div>

hi,

trying to find all xp computers in AD without including from a certain OU. this is pretty much a redundant question, since i know I could simply move an OU to make this work. but the point is to learn something, so i’ll ask anyway!

this

```
Get-ADComputer -Filter {OperatingSystem -like "Windows XP Professional"} -Property * -SearchBase {"ou=Admin Computers,ou=Computer Directory,dc=tdwh,dc=co,dc=uk"} not "ou=Inactive,ou=Computer Directory,dc=company,dc=co,dc=uk"} | Format-Table Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion -Wrap -Auto
```

doesn’t work.

this

```
Get-ADComputer -Filter {OperatingSystem -like "Windows XP Professional"} -Property * -SearchBase "ou=Admin Computers,ou=Computer Directory,dc=tdwh,dc=co,dc=uk" -SearchBase -"ou=Inactive,ou=Computer Directory,dc=company,dc=co,dc=uk" | Format-Table Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion -Wrap -Auto
```

doesn’t work. substituting the word not for the - minus sign doesn’t work. fairly new to PS so not 100% sure what the correct syntax will be, or if its actually possible.

---

<div class="post-metadata">

**Author:** ![bytejunkie](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/bytejunkie/32/813_2.png) [@bytejunkie](https://forums.powershell.org/u/bytejunkie)\
**Post date:** [December 18, 2014, 8:51pm UTC](https://forums.powershell.org/t/get-adcomputer-and-multiple-searchbase-parameters/3548/2 "2014-12-18T20:51:09Z")

</div>

just to be transparent, “Inactive” is an OU inside “Admin Computers OU”

---

<div class="post-metadata">

**Author:** ![matt-mcnabb](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-mcnabb](https://forums.powershell.org/u/matt-mcnabb)\
**Post date:** [December 18, 2014, 10:50pm UTC](https://forums.powershell.org/t/get-adcomputer-and-multiple-searchbase-parameters/3548/3 "2014-12-18T22:50:55Z")

</div>

-Searchbase does not accept multiple values, but you can use a pipeline with Foreach-Object to work around this limitation:

```
'ou=Inactive,ou=Computer Directory,dc=company,dc=co,dc=uk','ou=Admin Computers,ou=Computer Directory,dc=tdwh,dc=co,dc=uk' |
    ForEach-Object {get-adcomputer -Filter "OperatingSystem -like '*XP*'" -Property * -SearchBase $_}
```

Also, I once heard it said that friends don’t let friends use ‘-Properties \*’ and I think that’s solid advice. If you need properties beyond the ones provided in the default output, just get those properties.

---

<div class="post-metadata">

**Author:** ![daniel-krebs](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/daniel-krebs/32/484_2.png) [@daniel-krebs](https://forums.powershell.org/u/daniel-krebs)\
**Post date:** [December 18, 2014, 11:08pm UTC](https://forums.powershell.org/t/get-adcomputer-and-multiple-searchbase-parameters/3548/4 "2014-12-18T23:08:59Z")

</div>

Here is an alternative:

```
$ADComputerProperties = @('Name','OperatingSystem','OperatingSystemServicePack','OperatingSystemVersion')
Get-ADComputer -Filter {OperatingSystem -like '*XP*'} -SearchBase 'dc=tdwh,dc=co,dc=uk' -Properties $ADComputerProperties | 
    Where-Object -FilterScript { $_.DistinguishedName -notlike 'CN=*,OU=Inactive,*' } | 
        Format-Table -Property $ADComputerProperties -Wrap -Auto
```

1st you get all the XP computers in whatever OU they are located in your domain and 2nd you let PowerShell do the filtering using the Where-Object cmdlet and a -notlike operator. The result should be a table with XP computers excluding any “Inactive” child OU.

---

<div class="post-metadata">

**Author:** ![bytejunkie](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/bytejunkie/32/813_2.png) [@bytejunkie](https://forums.powershell.org/u/bytejunkie)\
**Post date:** [December 19, 2014, 1:07am UTC](https://forums.powershell.org/t/get-adcomputer-and-multiple-searchbase-parameters/3548/5 "2014-12-19T01:07:27Z")

</div>

two awesome responses, thanks guys. used the last one to great effect.

looks like the kind of plae i can learn, so probably gonna spend the rest of the afternoon doing a bit of research.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:46pm UTC](https://forums.powershell.org/t/get-adcomputer-and-multiple-searchbase-parameters/3548/6 "2024-05-16T20:46:37Z")

</div>


