![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Pls help me create a CSV named from a varible in VBS Hi, I'm trying to create a csv file that is named after the data I'm trying to pass data to. I want a script that finds the server hostname and then creates a CSV file based on that name. I'm using VBS and WMI to find the machine's host name and I'll be adding a load more objects later (which i why I chose to use WMI). This script will eventually form an audit of a server. I know how to create a CSV file and pass data to it, I just can't seem to work out how to rename the file as a varible: On Error Resume Next Set objFS = CreateObject("Scripting.FileSystemObject") Set objNewFile = objFS.CreateTextFile("Audit.csv") 'HostName strComputer = "." Set HN = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = HN.ExecQuery( _ "SELECT * FROM Win32_OperatingSystem",,48) Set HostName = objItem.CSName For Each objItem in colItems Wscript.Echo objItem.CSName & "," Next objFile.Close Can anyone help me? Regards, Gareth Cooper -- "Science is what we hope for...Technology is what we get stuck with" |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Pls help me create a CSV named from a varible in VBS opps... I had an Echo there when I needed a Write, For Each objItem in colItems objNewFile.Write objItem.CSName & "," -- "Science is what we hope for...Technology is what we get stuck with" "GazzaJagman" wrote: Quote: > Hi, > I'm trying to create a csv file that is named after the data I'm trying to > pass data to. > I want a script that finds the server hostname and then creates a CSV file > based on that name. I'm using VBS and WMI to find the machine's host name and > I'll be adding a load more objects later (which i why I chose to use WMI). > This script will eventually form an audit of a server. I know how to create a > CSV file and pass data to it, I just can't seem to work out how to rename the > file as a varible: > > On Error Resume Next > Set objFS = CreateObject("Scripting.FileSystemObject") > Set objNewFile = objFS.CreateTextFile("Audit.csv") > > 'HostName > strComputer = "." > Set HN = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") > Set colItems = HN.ExecQuery( _ > "SELECT * FROM Win32_OperatingSystem",,48) > Set HostName = objItem.CSName > For Each objItem in colItems > Wscript.Echo objItem.CSName & "," > Next > > objFile.Close > > Can anyone help me? > > Regards, > > Gareth Cooper > > -- > "Science is what we hope for...Technology is what we get stuck with" |
My System Specs![]() |
| | #3 (permalink) |
| | RE: Pls help me create a CSV named from a varible in VBS Sorted! I worked it out through trial and error (mostly errors). I used: On Error Resume Next Set objFS = CreateObject("Scripting.FileSystemObject") Dim strComputer 'HostName' strComputer = "." Set HN = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = HN.ExecQuery( _ "SELECT * FROM Win32_OperatingSystem",,48) For Each objItem in colItems Set objNewFile = objFS.CreateTextFile(objItem.CSName & ".CSV") objNewFile.WriteLine "HostName, " objNewFile.Write objItem.CSName & "," Next objNewFile.Close This script looks up a Server's hostname and then creates a CSV file using the Hostname as a filename. It then populates the CSV file with a heading of Hostname, followed by the entry. Regards, Gareth Cooper -- "Science is what we hope for...Technology is what we get stuck with" "GazzaJagman" wrote: Quote: > opps... > I had an Echo there when I needed a Write, > > For Each objItem in colItems > objNewFile.Write objItem.CSName & "," > > -- > "Science is what we hope for...Technology is what we get stuck with" > > > "GazzaJagman" wrote: > Quote: > > Hi, > > I'm trying to create a csv file that is named after the data I'm trying to > > pass data to. > > I want a script that finds the server hostname and then creates a CSV file > > based on that name. I'm using VBS and WMI to find the machine's host name and > > I'll be adding a load more objects later (which i why I chose to use WMI). > > This script will eventually form an audit of a server. I know how to create a > > CSV file and pass data to it, I just can't seem to work out how to rename the > > file as a varible: > > > > On Error Resume Next > > Set objFS = CreateObject("Scripting.FileSystemObject") > > Set objNewFile = objFS.CreateTextFile("Audit.csv") > > > > 'HostName > > strComputer = "." > > Set HN = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") > > Set colItems = HN.ExecQuery( _ > > "SELECT * FROM Win32_OperatingSystem",,48) > > Set HostName = objItem.CSName > > For Each objItem in colItems > > Wscript.Echo objItem.CSName & "," > > Next > > > > objFile.Close > > > > Can anyone help me? > > > > Regards, > > > > Gareth Cooper > > > > -- > > "Science is what we hope for...Technology is what we get stuck with" |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: re-named folders by WLM | Live Mail | |||
| Un-named trojan | Live Messenger | |||
| Files named WindowsLiveContact | Vista General | |||
| Local $varible scope? | PowerShell | |||
| Multiple Named Networks | Vista networking & sharing | |||