Re: Memory output format



Because ADO returns description as an array, you still need the "For Each"
loop to retrieve the value. And you need to set strDescription to a blank
string if the array is Null, or you will retain the value from the previous
computer. All values must be retrieved in the "Do Until" loop, so you get
new values for each computer. If I understand, the following should work:
===================
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, sAMAccountName, operatingSystem, description " _
& "from 'LDAP://DC=<mydomain>,DC=com' " _
& "Where objectCategory='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "Computer OS: " &
objRecordSet.Fields("operatingSystem").Value

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 "NetBIOS Name: " & strName
Wscript.Echo "Description: " & strDescription
objRecordSet.MoveNext
Loop
objRecordSet.Close
objConnection.Close

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"Rick" <drummer10980@xxxxxxxxx> wrote in message
news:1165583831.263805.53630@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Richard,
I am using your script in the middle of a script pulling wmi info from
a list of servers in a text file. I put this script in it and took out
the Do loop
for the arrdesc. this gives me the description of the first server in
AD. how do I zero in on the current server in my list that I am
collecting information on and writing out to a file.

thanks again
Rick

Richard Mueller wrote:
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: vbscript, searching Active directory using ADODB type mismatch error
    ... The LastLogon program goes to extra effort to retrieve the LastLogon dates ... final loop and retrieve the desired attributes. ... into your original last logon dates vb script from your web site. ...
    (microsoft.public.windows.server.scripting)
  • Re: Help with reading remote registries
    ... Derek wrote: ... > I am having trouble with the following script. ... > searching the local computer but will not retrieve the registry key ... will make the script go into a eternal loop (remove the "On Error ...
    (microsoft.public.scripting.vbscript)
  • 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: Memory output format
    ... 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 ... I'm having another issue with my script. ... FormatNumber strTotalPhysicalMemory ...
    (microsoft.public.scripting.wsh)