Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

code runs without error and without results

$
0
0

This code Works.

 

 $Searcher = New-Object DirectoryServices.DirectorySearcher

$Searcher.Filter = '(&(objectCategory=computer)(anr=mg10011001))'

$Searcher.SearchRoot = 'LDAP://DC=Acme,DC=org'

$Searcher.FindAll()

 

It will return the OU path where my workstation lives.  My workstation is mg10011001

 

But when I grab the computer name from a registry key and try to use a variable my code runs without error but nothing is returned.

 

$GetName = (get-ItemProperty hklm:\SOFTWARE\Microsoft\MPSD\OSD).OSDComputerName 

$Searcher = New-Object DirectoryServices.DirectorySearcher

$Searcher.Filter = '(&(objectCategory=computer)(anr=$GetName))'

$Searcher.SearchRoot = 'LDAP://DC=Acme,DC=org'

$Searcher.FindAll()

 

How come?  


Viewing all articles
Browse latest Browse all 8411

Latest Images

Trending Articles



Latest Images