Re: Memory output format



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



.



Relevant Pages

  • Re: Memory output format
    ... And you need to set strDescription to a blank ... All values must be retrieved in the "Do Until" loop, ... I am using your script in the middle of a script pulling wmi info from ... The error is raised when the program attempts to retrieve the value of the ...
    (microsoft.public.scripting.wsh)
  • Re: Memory output format
    ... And you need to set strDescription to a blank ... All values must be retrieved in the "Do Until" loop, ... I am using your script in the middle of a script pulling wmi info from ... The error is raised when the program attempts to retrieve the value of the ...
    (microsoft.public.scripting.wsh)
  • Re: Force password Expiration to 5 days
    ... Then when the day arrives you can run a script or program that either: ... Expires everyones password, ... I have a VBScript program that converts ... A filter to retrieve all users that have not change their password since ...
    (microsoft.public.windows.server.scripting)
  • Re: AD users manage
    ... you do not bind to the object objUser in the script. ... actually retrieve the value). ... Set objConnection = CreateObject ... object with the given value for sAMAccountName. ...
    (microsoft.public.windows.server.scripting)
  • Re: AD users manage
    ... you do not bind to the object objUser in the script. ... retrieve the value of the attribute sAMAccountName (although you don't ... actually retrieve the value). ... Set objConnection = CreateObject ...
    (microsoft.public.windows.server.scripting)

Loading