Re: Memory output format
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 7 Dec 2006 11:02:36 -0600
Rick,
The error is raised when the program attempts to retrieve the value of the
sAMAccountName attribute, but that attribute is not listed in the query as
one of the attribute values to retrieve. Also, you retrieve Name and
operatingSystem outside the "Do Until" loop. This will retrieve these values
only for the first computer in the recordset. These statements should be in
the "Do Until" loop. I would suggest something similar to below. I added
sAMAccountName to the list of attribute values to retrieve, and moved the
retrieval of all values into the "Do Until" loop.
' ...
objCommand.CommandText = _
"Select Name, operatingSystem, sAMAccountName, description " _
& "from 'LDAP://DC=<mydomain>,DC=com' " _
& "Where objectClass='computer'"
' ...
Do Until objRecordSet.EOF
Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "Computer OS: " &
objRecordSet.Fields("operatingSystem").Value
Wscript.Echo "NetBIOS Name: " &
objRecordSet.Fields("sAMAccountName").Value
arrDesc = objRecordSet.Fields("description").Value
If IsNull(arrDesc) Then
strDescription = ""
Else
For Each strLine In arrDesc
strDescription = strLine
Next
End If
Wscript.Echo "Description: " & strDescription
objRecordSet.MoveNext
Loop
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
"Rick" <drummer10980@xxxxxxxxx> wrote in message
news:1165413359.742443.248070@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks Richard, that worked.
I'm having another issue with my script. the script I'm using is doing
WMI calls for different WS items. Memory, OS etc. I need to grab the
computer description from AD and found one of your scripts to do this.
I am trying to run the following script. and I get the following error.
Item cannot be found in the collection corresponding to the requested
name or ordinal.
I get the computer name and os, but is seems to fail on pulling the
computer description.
I've done a search on the error, but no luck.
any ideas?
Thanks
Rick
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, operatingSystem, description from
'LDAP://DC=<mydomain>,DC=com' " _
& "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "Computer OS: " &
objRecordSet.Fields("operatingSystem").Value
Do Until objRecordSet.EOF
strName = objRecordSet.Fields("sAMAccountName").Value
arrDesc = objRecordSet.Fields("description").Value
If IsNull(arrDesc) Then
strDescription = ""
Else
For Each strLine In arrDesc
strDescription = strLine
Next
End If
Wscript.Echo strName & ", " & strDescription
objRecordSet.MoveNext
Loop
Reply »
Richard Mueller wrote:
FormatNumber is a function, but you have used it as sub. Try:
For Each objItem in colItems
strTotalPhysicalMemory = objItem.TotalPhysicalMemory
WScript.Echo FormatNumber(strTotalPhysicalMemory, 0)
Next
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
"Rick" <drummer10980@xxxxxxxxx> wrote in message
news:1165343414.537645.133610@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Richard,
thanks for the response, I'm new at this and apprieciate the help. I am
using the following inside a script when I run the formatnumber with
parentheses I get the following error.
Cannot use parentheses when calling a Sub
I take out the parentheses, the script runs but does not format the
number. what could I look at?
Rick
Set colItems = objWMIService.ExecQuery("Select * from
Win32_ComputerSystem",,48)
For Each objItem in colItems
strTotalPhysicalMemory = objItem.TotalPhysicalMemory
FormatNumber strTotalPhysicalMemory
WScript.Echo strTotalPhysicalMemory
Richard Mueller wrote:
Rick wrote:
I'm trying to format a string in a VB Script for amount of memory I
am
getting from a server. the string is 1073197056, I need to have it
show
as a readable number, say 1 gig, I also will have the problem for
systems with 512 and 2 gig etc. Is there a conversion I can do on
these
numbers
You can display the number with commas, which makes it much easier to
read,
with the FormatNumber function:
lngValue = 1073197056
Wscript.Echo FormatNumber(lngValue, 0)
You can also convert bytes to gigabytes by dividing by 2^30
(1,073,741,824).
Wscript.Echo FormatNumber(lngValue/2^30, 3)
The second parameter in the FormatNumber function is the number of
digits
to
display after the decimal.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
.
- Follow-Ups:
- Re: Memory output format
- From: Rick
- Re: Memory output format
- References:
- Memory output format
- From: Rick
- Re: Memory output format
- From: Richard Mueller
- Re: Memory output format
- From: Rick
- Re: Memory output format
- From: Richard Mueller
- Re: Memory output format
- From: Rick
- Memory output format
- Prev by Date: Can't schedule Task with script on Windows 2000
- Next by Date: Re: "Microsoft VBScript runtime error: Object required: 'WshShell'
- Previous by thread: Re: Memory output format
- Next by thread: Re: Memory output format
- Index(es):
Relevant Pages
|
Loading