Dutchict
asked on
Help needed with script
Hi there guys,
I have made some code in VB to make a fast report on a customer server. I would like to add memory information and cpu usage (suggestions?)
The bif question, i run this script from the Scriptomagic tool from scripting guys, but how can i run this from a file on windows with HTML output?
And how can i create a code to view critical en warnings from the event viewer from the last 2 weeks?
Thanks in advance!
I have made some code in VB to make a fast report on a customer server. I would like to add memory information and cpu usage (suggestions?)
The bif question, i run this script from the Scriptomagic tool from scripting guys, but how can i run this from a file on windows with HTML output?
And how can i create a code to view critical en warnings from the event viewer from the last 2 weeks?
Thanks in advance!
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array(".")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "<b>JMS</b>: " & "Checklist"
WScript.Echo "=========================================="
WScript.Echo "<b>Informatie:</b>"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo"Klant: " & objItem.Organization
next
WScript.Echo"Datum: " & (FormatDateTime(Date(),1))
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo"Server: " & objItem.CSName
next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
WScript.Echo "IP adres: "& IPConfig.IPAddress(i)
Next
End If
Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "OS: " & objItem.Caption
Next
Set oWMI = GetObject("winmgmts://./root/cimv2")
Set cI = oWMI.ExecQuery("Select * from Win32_OperatingSystem", , 48)
For Each oI in cI
Dim sY, sM, sD, sH, sN, sS, dU, sT, iD, iH, iM, iSS
'yyyymmddHHMMSS
sY = Left(oI.LastBootUpTime,4)
sM = Mid(oI.LastBootUpTime, 5, 2)
sD = Mid(oI.LastBootUpTime, 7, 2)
sH = Mid(oI.LastBootUpTime, 9, 2)
sN = Mid(oI.LastBootUpTime,11, 2)
sS = Mid(oI.LastBootUpTime,13, 2)
dU = DateSerial(sY, sM, sD) + TimeSerial(sH, sN, sS)
iM = DateDiff("n", dU, Now)
iD = iM \ 1440
iM = iM - (iD * 1440)
iH = iM \ 60
iM = iM - (iH * 60)
Next
WScript.Echo "Laatste boot: " & iD & " dagen, " & iH & " uren en " & iM & " minuten"
WScript.Echo"<b>Schijfbeheer:</b>"
Const HARD_DISK = 3
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")
For Each objDisk in colDisks
Wscript.Echo "Partitie: "& objDisk.DeviceID
Wscript.Echo "Vrije disk ruimte: "& objDisk.FreeSpace
Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = 3")
For Each objDisk in colDisks
intFreeSpace = objDisk.FreeSpace
intTotalSpace = objDisk.Size
pctFreeSpace = intFreeSpace / intTotalSpace
Wscript.Echo objDisk.DeviceID, FormatPercent(pctFreeSpace)
Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
WScript.Echo"<b>Processor:</b>"
For Each objItem In colItems
WScript.Echo "Processor: " & objItem.Name
WScript.Echo
Next
Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PageFileSetting", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
WScript.Echo"<b>Pagefile:</b>"
For Each objItem In colItems
WScript.Echo "Grootte: " & objItem.InitialSize
WScript.Echo "Maximumgrootte: " & objItem.MaximumSize
WScript.Echo "Locatie: " & objItem.Name
WScript.Echo
Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
WScript.Echo"<b>Operating System:</b>"
For Each objItem In colItems
WScript.Echo "Opstartschijf: " & objItem.BootDevice
WScript.Echo "Bouwnummer: " & objItem.BuildNumber
WScript.Echo "Operating System: " & objItem.Caption
WScript.Echo "Service Pack: " & objItem.CSDVersion
WScript.Echo "Computernaam: " & objItem.CSName
WScript.Echo "Installatie Datum: " & WMIDateStringToDate(objItem.InstallDate)
WScript.Echo "Bouwer: " & objItem.Manufacturer
WScript.Echo "OS Locatie: " & objItem.Name
WScript.Echo "Bedrijf: " & objItem.Organization
WScript.Echo "Geregistreerd: " & objItem.RegisteredUser
WScript.Echo "Serienummer: " & objItem.SerialNumber
WScript.Echo "Versie: " & objItem.Version
WScript.Echo "Windows Directory: " & objItem.WindowsDirectory
WScript.Echo
Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_MappedLogicalDisk", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
WScript.Echo" "
WScript.Echo"<b>Mappings:</b> "
For Each objItem In colItems
WScript.Echo "Drive: " & objItem.Caption
WScript.Echo "Bestandssysteem: " & objItem.FileSystem
WScript.Echo "Vrije ruimte: " & objItem.FreeSpace
WScript.Echo "Doel: " & objItem.ProviderName
WScript.Echo "Grootte: " & objItem.Size
WScript.Echo "Drive naam: " & objItem.VolumeName
WScript.Echo
Next
Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
& " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function
ASKER
RobSampson, thanks for your reaction. Important is the HTML output. For the memory i found some samples myself, i guess i can find cpu to. My biggest problem is to get HTML output. If that is running i can create a *.exe from this script and place the script on the customer machine.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Yes, it works great! So no more Wscript.Echo but strHTML, i award you the promised points, thanks again!
ASKER
Solution is working great, i do have to trie to inderstand this method to add more scripts.
Yes, that's right. You basically just need to store the HTML code in a variable as you go along with your output (you could write each line directly to the file, but I find this cleaner).
Then at the end of the script, you just write the HTML code to a file.
Thanks for the grade. Let me know if you post any more related questions to this. I will try to help out. Just post a link to that question here.
Rob.
Then at the end of the script, you just write the HTML code to a file.
Thanks for the grade. Let me know if you post any more related questions to this. I will try to help out. Just post a link to that question here.
Rob.
ASKER
Hi, well, i have the same trouble to another script, only the change wscript.echo to strhtml and place it into the other file woudnt help..
' Search for Software Updates
Set objSearcher = CreateObject("Microsoft.Update.Searcher")
Set objResults = objSearcher.Search("Type='Software'")
Set colUpdates = objResults.Updates
For i = 0 to colUpdates.Count - 1
Wscript.Echo "Title: " & colUpdates.Item(i).Title
Wscript.Echo "Autoselect on Web sites: " & _
colUpdates.Item(i).AutoSelectOnWebSites
For Each strUpdate in colUpdates.Item(i).BundledUpdates
Wscript.Echo "Bundled update: " & strUpdate
Next
Wscript.Echo "Can require source: " & colUpdates.Item(i).CanRequireSource
Set objCategories = colUpdates.Item(i).Categories
For z = 0 to objCategories.Count - 1
Wscript.Echo "Category name: " & objCategories.Item(z).Name
Wscript.Echo "Category ID: " & objCategories.Item(z).CategoryID
For Each strChild in objCategories.Item(z).Children
Wscript.Echo "Child category: " & strChild
Next
Wscript.Echo "Category description: " & _
objCategories.Item(z).Description
Wscript.Echo "Category order: " & objCategories.Item(z).Order
Wscript.Echo "Category type: " & objCategories.Item(z).Type
Next
Wscript.Echo "Deadline: " & colUpdates.Item(i).Deadline
Wscript.Echo "Delta compressed content available: " & _
colUpdates.Item(i).DeltaCompressedContentAvailable
Wscript.Echo "Delta compressed content preferred: " & _
colUpdates.Item(i).DeltaCompressedContentPreferred
Wscript.Echo "Description: " & colUpdates.Item(i).Description
Wscript.Echo "EULA accepted: " & colUpdates.Item(i).EULAAccepted
Wscript.Echo "EULA text: " & colUpdates.Item(i).EULAText
Wscript.Echo "Handler ID: " & colUpdates.Item(i).HandlerID
Set objIdentity = colUpdates.Item(i).Identity
Wscript.Echo "Revision number: " & objIdentity.RevisionNumber
Wscript.Echo "Update ID: " & objIdentity.UpdateID
Set objInstallationBehavior = colUpdates.Item(i).InstallationBehavior
Wscript.Echo "Can request user input: " & _
objInstallationBehavior.CanRequestUserInput
Wscript.Echo "Impact: " & objInstallationBehavior.Impact
Wscript.Echo "Reboot behavior: " & objInstallationBehavior.RebootBehavior
Wscript.Echo "Requires network connectivity: " & _
objInstallationBehavior.RequiresNetworkConnectivity
Wscript.Echo "Is beta: " & colUpdates.Item(i).IsBeta
Wscript.Echo "Is hidden: " & colUpdates.Item(i).IsHidden
Wscript.Echo "Is installed: " & colUpdates.Item(i).IsInstalled
Wscript.Echo "Is mandatory: " & colUpdates.Item(i).IsMandatory
Wscript.Echo "Is uninstallable: " & colUpdates.Item(i).IsUninstallable
For Each strLanguage in colUpdates.Item(i).Languages
Wscript.Echo "Supported language: " & strLanguage
Next
Wscript.Echo "Last deployment change time: " & _
colUpdates.Item(i).LastDeploymentChangeTime
Wscript.Echo "Maximum download size: " & colUpdates.Item(i).MaxDownloadSize
Wscript.Echo "Minimum download size: " & colUpdates.Item(i).MinDownloadSize
Wscript.Echo "Microsoft Security Response Center severity: " & _
colUpdates.Item(i).MsrcSeverity
Wscript.Echo "Recommended CPU speed: " & _
colUpdates.Item(i).RecommendedCPUSpeed
Wscript.Echo "Recommended hard disk space: " & _
colUpdates.Item(i).RecommendedHardDiskSpace
Wscript.Echo "Recommended memory: " & colUpdates.Item(i).RecommendedMemory
Wscript.Echo "Release notes: " & colUpdates.Item(i).ReleaseNotes
Wscript.Echo "Support URL: " & colUpdates.Item(i).SupportURL
Wscript.Echo "Type: " & colUpdates.Item(i).Type
Wscript.Echo "Uninstallation notes: " & _
colUpdates.Item(i).UninstallationNotes
x = 1
For Each strStep in colUpdates.Item(i).UninstallationSteps
Wscript.Echo x & " -- " & strStep
x = x + 1
Next
For Each strArticle in colUpdates.Item(i).KBArticleIDs
Wscript.Echo "KB article: " & strArticle
Next
Wscript.Echo "Deployment action: " & colUpdates.Item(i).DeploymentAction
Wscript.Echo
Next
Rob.