So I tried and made the script using the dictionary method, it works but on each new line it writes User - Computer - One software.
But the output I need is the same as Case 1 on your first post so User1 - Computer1 - All software on computer1
next line: If user1 has more computers then: Computer2 (next line computer3,4... - all soft on computer2(next line 3,4...)
if not then User2 - Computer1 - all software on computer1
next line: If user2 has more computers then: Computer2 (next line computer3,4... - all soft on computer2(next line 3,4...)
if not then User3 - Computer1 - all software on computer1
etc.
If I don't use the loop, it only writes the first line in the output file. Also tried to put the loop on different places in the script but it's not much better.
Can you please take a look on the code and tell me where did I go wrong ? (If you can tell me how to paste the code so it actually looks like code I will gladly repost it, can't figure it out, I'm pasting it from PrimalScript)
Thanks
------------------------------------------------------------------------------------------------------------------------------------------------------
Option Explicit
Dim objExcel, strExcelPath, objSheet
Dim filesys, fWrt, isSubsequentLine
Dim strUser, vNewRow, strSoftware, strComputer
Dim user, computer, inventory, software
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application")
strExcelPath = "D:\input.csv"
objExcel.Workbooks.Open strExcelPath
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objExcel.visible=False
vNewRow = 2
Do While objSheet.Cells(vNewRow, 1).Value <> ""
strUser = objSheet.Cells(vNewRow, 3)
strComputer = objSheet.Cells(vNewRow, 1)
strSoftware = objSheet.Cells(vNewRow, 2)
user = strUser
computer = strComputer
software = strSoftware
Set inventory = CreateObject("Scripting.Dictionary")
inventory.Add user, CreateObject("Scripting.Dictionary")
inventory(user).Add computer, CreateObject("Scripting.Dictionary")
inventory(user)(computer).Add software, True
WScript.Echo Join(inventory(user)(computer).Keys)
Set fWrt = filesys.opentextfile ("D:\output.csv", ForAppending, True)
For Each user In inventory.Keys
isSubsequentLine = False
For Each computer In inventory(user).Keys
If isSubsequentLine Then
fWrt.WriteLine "," & computer & "," & Join(inventory(user)(computer).Keys, ", ")
fWrt.Close
Else
fWrt.WriteLine user & "," & computer & "," & Join(inventory(user)(computer).Keys, ", ")
fWrt.Close
isSubsequentLine = True
End If
Next
Next
vNewRow = vNewRow + 1
Loop
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
wscript.quit
------------------------------------------------------------------------------------------------------------------------------------------------------
<message edited by Thrinn on Tuesday, December 06, 2011 8:06 AM>