Solved

Help with scripting problem

Posted on 2014-04-02
12
367 Views
Last Modified: 2014-04-03
Can some please help me out with this problem?

error:
Missing ')' in method call.
At H:\scripting\powershell\fqdmtestscom.ps1:75 char:13
+ Write-Host " <<<< LDAP Elapsed milliseconds $($ts.Milliseconds)" -ForegroundColor Red
    + CategoryInfo          : ParserError: (CloseParenToken:TokenId) [], ParseException
    + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall

Script:



$domain = ‘LDAP://my.domain.com’

$agent = ‘scom.domain.com’

 

$start = [DateTime]::Now

 

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher

$objSearcher.SearchRoot = $domain

$objSearcher.PageSize = 1000

$objSearcher.Filter = “(&(dNSHostName=$agent)(objectClass=computer))

$objSearcher.SearchScope = “SubTree”

 

$colProplist = “name”,“objectSID”

foreach ($i in $colPropList)

{

    $objSearcher.PropertiesToLoad.Add($i) | Out-Null

}

 

$objSearcher.CacheResults=$false

 

$colResults = $objSearcher.FindAll()

 

$ts = New-TimeSpan -Start $start -End ([DateTime]::Now)

$prop = $colResults.Properties

Write-Host “First LDAP Elapsed milliseconds $($ts.Milliseconds)“ -ForegroundColor Yellow

 

$sid = $prop.Item(‘objectSID’)

$txtSid = ([System.BitConverter]::ToString($sid[0])).Replace(‘-’, ”)

 

 

$agentLookup = $domain + ‘/<SID=’ + $txtSid + ‘>’

$start = [DateTime]::Now

$res = [ADSI] $agentLookup

$res | gm | Out-Null

Write-Host ‘Got: ‘ $res.dNSHostName

$ts = New-TimeSpan -Start $start -End ([DateTime]::Now)

 

Write-Host “LDAP Elapsed milliseconds $($ts.Milliseconds)“ -ForegroundColor Red
0
Comment
Question by:hlaten
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39972272
Check this line:

$txtSid = ([System.BitConverter]::ToString($sid[0])).Replace(‘-’," ”)

Are you missing " in your code?
0
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 39972318
$domain = ‘LDAP://my.domain.com’

$agent = ‘scom.domain.com’

 

$start = [DateTime]::Now

 

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher

$objSearcher.SearchRoot = $domain

$objSearcher.PageSize = 1000

$objSearcher.Filter = “(&(dNSHostName=$agent)(objectClass=computer))”

$objSearcher.SearchScope = “SubTree”

 

$colProplist = “name”,“objectSID”

foreach ($i in $colPropList)

{

    $objSearcher.PropertiesToLoad.Add($i) | Out-Null

}

 

$objSearcher.CacheResults=$false

 

$colResults = $objSearcher.FindAll()

 

$ts = New-TimeSpan -Start $start -End ([DateTime]::Now)

$prop = $colResults.Properties

Write-Host “First LDAP Elapsed milliseconds $($ts.Milliseconds)“ -ForegroundColor Yellow

 

$sid = $prop.Item(‘objectSID’)

$txtSid = ([System.BitConverter]::ToString($sid[0])).Replace(‘-’,"")

 

 

$agentLookup = $domain + ‘/<SID=’ + $txtSid + ‘>’

$start = [DateTime]::Now

$res = [ADSI] $agentLookup

$res | gm | Out-Null

Write-Host "Got: " $res.dNSHostName

$ts = New-TimeSpan -Start $start -End ([DateTime]::Now)

 
 
Write-Host “LDAP Elapsed milliseconds $($ts.Milliseconds)“ -ForegroundColor Red 

Open in new window

0
 
LVL 29

Expert Comment

by:becraig
ID: 39972341
What are you hoping to accomplish with this script ?

It seems to me there might be much easier ways to get what you need.
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39972430
I think the property is $ts.Millisecond, not $ts.Milliseconds
0
 

Author Comment

by:hlaten
ID: 39972432
I am trying to find the ldap lookup time across trusting domains for SCOM 2012 server and agents assigned to domain controllers. If there is an easier way fine, please help. If you stick with the scripts is there also away to have the server defined in "$domain = ‘LDAP://" and the response time defined in a spreadsheet, (csv) or html report, showing server and response time? These domains are international domains aspread across the world.
0
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39972433
@Dan. $ts.Milliseconds  is right. please check the property again
@hlaten:   Is your script worked when you follow my comment . ie you missed " in one of the line i shown in my first comment.
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39972441
Yup.
It's date.Millisecond, timespan.Milliseconds.
Confusing, isn't it ? :)
0
 

Author Comment

by:hlaten
ID: 39972448
This is what I get when I run the script:

PS H:\scripting\powershell> ./fqdmtestscom.ps1
Exception calling "FindAll" with "0" argument(s): "There is no such object on the server.
"
At H:\scripting\powershell\fqdmtestscom.ps1:41 char:35
+ $colResults = $objSearcher.FindAll <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

First LDAP Elapsed milliseconds 359
You cannot call a method on a null-valued expression.
At H:\scripting\powershell\fqdmtestscom.ps1:53 char:18
+ $sid = $prop.Item <<<< (`objectSID')
    + CategoryInfo          : InvalidOperation: (Item:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Cannot index into a null array.
At H:\scripting\powershell\fqdmtestscom.ps1:55 char:49
+ $txtSid = ([System.BitConverter]::ToString($sid[ <<<< 0])).Replace(`-',"")
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Got:
LDAP Elapsed milliseconds 6
PS H:\scripting\powershell>
0
 
LVL 29

Expert Comment

by:becraig
ID: 39972457
Can you say what you're trying to do we can maybe find an easier way.
0
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39972469
update:

$objSearcher.SearchRoot="LDAP://dc=MyDomain, dc=com"
0
 

Author Comment

by:hlaten
ID: 39972583
Still get this:

PS H:\scripting\powershell> ./fqdmtestscom.ps1
First LDAP Elapsed milliseconds 429
You cannot call a method on a null-valued expression.
At H:\scripting\powershell\fqdmtestscom.ps1:54 char:18
+ $sid = $prop.Item <<<< (`objectSID')
    + CategoryInfo          : InvalidOperation: (Item:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Cannot index into a null array.
At H:\scripting\powershell\fqdmtestscom.ps1:56 char:49
+ $txtSid = ([System.BitConverter]::ToString($sid[ <<<< 0])).Replace(`-',"")
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Got:
LDAP Elapsed milliseconds 430
PS H:\scripting\powershell>
0
 

Author Closing Comment

by:hlaten
ID: 39975084
The task was succesful.
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question