Author Posts

February 25, 2016 at 7:09 am

Hi,
Can someone help me please?

I can't get this to Work:

#1

$strSearchBase = $strOU + $srtDomain

$Computers = get-adcomputer -filter * -searchbase $strSearchBase | select dnshostname

I get this error:
get-adcomputer : Directory object not found

But this Works perfectly:

#2

$strSearchBase = β€œou=Database servere, ou=Domain Servere, dc=egedal, dc=egekom, dc=org”

$Computers = get-adcomputer -filter * -searchbase $strSearchBase | select dnshostname

In #1 when I make Write-host $strSearchBase I get this in the console:

ou=Domain Servere, ou=Database servere, dc=egedal, dc=egekom, dc=org

So the two string should be tha same???

February 25, 2016 at 7:27 am

Depends on what's in your $strOU and $srtDomain variables. (And is that a typo, supposed to be $strDomain?)

February 25, 2016 at 8:22 am

@dave Wyatt

$strSearchBase = $strOU + $srtDomain
Write-host $strSearchBase

ou=Domain Servere, ou=Database servere, dc=egedal, dc=egekom, dc=org

February 25, 2016 at 8:29 am

Yes it's a typo, but this is not the cause of the problem πŸ™‚

February 25, 2016 at 8:56 am

I still can't get it to work

February 25, 2016 at 2:48 pm

Looks to be absolutely correct, if your variables are as follows. Remember the last , in $strOU.

$strOU = 'ou=Domain Servere, ou=Database servere, '
$srtDomain = 'dc=egedal, dc=egekom, dc=org'
$strSearchBase = $strOU + $srtDomain

You could also combine your variables with double quotes. That shouldn't make a difference but it looks nice and you can also drop that trailing space from $strOU.
As if the spaces would even matter in this case.

$strOU = 'ou=Domain Servere, ou=Database servere,'
$srtDomain = 'dc=egedal, dc=egekom, dc=org'
$strSearchBase = "$strOU $srtDomain"

February 26, 2016 at 6:38 am

It's working now. I had accidently reversed the order of the OU's in the strOU string.

Thanks for the input guys πŸ™‚