Harrison Aten
asked on
Help with scripting problem
Can some please help me out with this problem?
error:
Missing ')' in method call.
At H:\scripting\powershell\fq dmtestscom .ps1:75 char:13
+ Write-Host " <<<< LDAP Elapsed milliseconds $($ts.Milliseconds)" -ForegroundColor Red
+ CategoryInfo : ParserError: (CloseParenToken:TokenId) [], ParseException
+ FullyQualifiedErrorId : MissingEndParenthesisInMet hodCall
Script:
$domain = ‘LDAP://my.domain.com’
$agent = ‘scom.domain.com’
$start = [DateTime]::Now
$objSearcher = New-Object System.DirectoryServices.D irectorySe archer
$objSearcher.SearchRoot = $domain
$objSearcher.PageSize = 1000
$objSearcher.Filter = “(&(dNSHostName=$agent)(ob jectClass= computer)) ”
$objSearcher.SearchScope = “SubTree”
$colProplist = “name”,“objectSID”
foreach ($i in $colPropList)
{
$objSearcher.PropertiesToL oad.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]::To String($si d[0])).Rep lace(‘-’, ”)
$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
error:
Missing ')' in method call.
At H:\scripting\powershell\fq
+ Write-Host " <<<< LDAP Elapsed milliseconds $($ts.Milliseconds)" -ForegroundColor Red
+ CategoryInfo : ParserError: (CloseParenToken:TokenId) [], ParseException
+ FullyQualifiedErrorId : MissingEndParenthesisInMet
Script:
$domain = ‘LDAP://my.domain.com’
$agent = ‘scom.domain.com’
$start = [DateTime]::Now
$objSearcher = New-Object System.DirectoryServices.D
$objSearcher.SearchRoot = $domain
$objSearcher.PageSize = 1000
$objSearcher.Filter = “(&(dNSHostName=$agent)(ob
$objSearcher.SearchScope = “SubTree”
$colProplist = “name”,“objectSID”
foreach ($i in $colPropList)
{
$objSearcher.PropertiesToL
}
$objSearcher.CacheResults=
$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]::To
$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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What are you hoping to accomplish with this script ?
It seems to me there might be much easier ways to get what you need.
It seems to me there might be much easier ways to get what you need.
I think the property is $ts.Millisecond, not $ts.Milliseconds
ASKER
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.
@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.
@hlaten: Is your script worked when you follow my comment . ie you missed " in one of the line i shown in my first comment.
Yup.
It's date.Millisecond, timespan.Milliseconds.
Confusing, isn't it ? :)
It's date.Millisecond, timespan.Milliseconds.
Confusing, isn't it ? :)
ASKER
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\fq dmtestscom .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\fq dmtestscom .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\fq dmtestscom .ps1:55 char:49
+ $txtSid = ([System.BitConverter]::To String($si d[ <<<< 0])).Replace(`-',"")
+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Got:
LDAP Elapsed milliseconds 6
PS H:\scripting\powershell>
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\fq
+ $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\fq
+ $sid = $prop.Item <<<< (`objectSID')
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Cannot index into a null array.
At H:\scripting\powershell\fq
+ $txtSid = ([System.BitConverter]::To
+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Got:
LDAP Elapsed milliseconds 6
PS H:\scripting\powershell>
Can you say what you're trying to do we can maybe find an easier way.
update:
$objSearcher.SearchRoot="L DAP://dc=M yDomain, dc=com"
$objSearcher.SearchRoot="L
ASKER
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\fq dmtestscom .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\fq dmtestscom .ps1:56 char:49
+ $txtSid = ([System.BitConverter]::To String($si d[ <<<< 0])).Replace(`-',"")
+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Got:
LDAP Elapsed milliseconds 430
PS H:\scripting\powershell>
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\fq
+ $sid = $prop.Item <<<< (`objectSID')
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Cannot index into a null array.
At H:\scripting\powershell\fq
+ $txtSid = ([System.BitConverter]::To
+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Got:
LDAP Elapsed milliseconds 430
PS H:\scripting\powershell>
ASKER
The task was succesful.
$txtSid = ([System.BitConverter]::To
Are you missing " in your code?