![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | writing output to log file from gwmi I'm trying to output the results from the following powershell script to a log file: $strComputer = Read-Host "Enter Machine name" $strDate = Get-Date -Format M.d.yyyy $csvFilePath = 'C:\' $strLog = New-Item -ItemType file $csvFilePath\$strComputer-$strDate.log -Force $software = gwmi -Namespace root\CIMV2 -Class Win32_Product -ComputerName $strComputer | Select Name, Version Add-Content $strLog $software What it places in the log file is the following : @{Name=VMware Tools; Version=3.1.1.3705} @{Name=MSXML 6 Service Pack 2 (KB954459); Version=6.20.1099.0} @{Name=Microsoft .NET Framework 3.0 Service Pack 1; Version=3.1.21022} @{Name=Microsoft .NET Framework 2.0 Service Pack 1; Version=2.1.21022} @{Name=Quarantine Server; Version=3.5.0} @{Name=Reporting Server (Symantec Corporation); Version=1.0.197.0} @{Name=CorpServerTuner; Version=6.0} @{Name=Windows Rights Management Client Backwards Compatibility SP2; Version=5.2.70} @{Name=Microsoft SQL Server Desktop Engine; Version=8.00.2039} @{Name=Windows Presentation Foundation; Version=3.0.6920.0} How do I get rid of the @{} stuff. I would just like to show the name of the software and the version number. |
My System Specs![]() |
| | #2 (permalink) |
| | RE: writing output to log file from gwmi You could try this Get-WmiObject -Class Win32_Product | Select Name, version | Export-Csv sw.txt -NoTypeInformation Import-Csv sw.txt Change the file names to yours -- Richard Siddaway All scripts are supplied "as is" and with no warranty PowerShell MVP Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "RG" wrote: Quote: > I'm trying to output the results from the following powershell script to a > log file: > > $strComputer = Read-Host "Enter Machine name" > $strDate = Get-Date -Format M.d.yyyy > $csvFilePath = 'C:\' > $strLog = New-Item -ItemType file $csvFilePath\$strComputer-$strDate.log > -Force > $software = gwmi -Namespace root\CIMV2 -Class Win32_Product -ComputerName > $strComputer | Select Name, Version > Add-Content $strLog $software > What it places in the log file is the following : > > @{Name=VMware Tools; Version=3.1.1.3705} > @{Name=MSXML 6 Service Pack 2 (KB954459); Version=6.20.1099.0} > @{Name=Microsoft .NET Framework 3.0 Service Pack 1; Version=3.1.21022} > @{Name=Microsoft .NET Framework 2.0 Service Pack 1; Version=2.1.21022} > @{Name=Quarantine Server; Version=3.5.0} > @{Name=Reporting Server (Symantec Corporation); Version=1.0.197.0} > @{Name=CorpServerTuner; Version=6.0} > @{Name=Windows Rights Management Client Backwards Compatibility SP2; > Version=5.2.70} > @{Name=Microsoft SQL Server Desktop Engine; Version=8.00.2039} > @{Name=Windows Presentation Foundation; Version=3.0.6920.0} > > How do I get rid of the @{} stuff. I would just like to show the name of > the software and the version number. > > |
My System Specs![]() |
| | #3 (permalink) |
| | RE: writing output to log file from gwmi You can't append informaton to a file using Export-Csv correct? I have a bunch of other information that I'm collecting in the script that is being placed into the file and I didn't see how I could use the Export-Csv since this isn't a one-line type of script. "RichS [MVP]" wrote: Quote: > You could try this > > > Get-WmiObject -Class Win32_Product | Select Name, version | Export-Csv > sw.txt -NoTypeInformation > Import-Csv sw.txt > > Change the file names to yours > > -- > Richard Siddaway > All scripts are supplied "as is" and with no warranty > PowerShell MVP > Blog: http://richardsiddaway.spaces.live.com/ > PowerShell User Group: http://www.get-psuguk.org.uk > > > "RG" wrote: > Quote: > > I'm trying to output the results from the following powershell script to a > > log file: > > > > $strComputer = Read-Host "Enter Machine name" > > $strDate = Get-Date -Format M.d.yyyy > > $csvFilePath = 'C:\' > > $strLog = New-Item -ItemType file $csvFilePath\$strComputer-$strDate.log > > -Force > > $software = gwmi -Namespace root\CIMV2 -Class Win32_Product -ComputerName > > $strComputer | Select Name, Version > > Add-Content $strLog $software > > What it places in the log file is the following : > > > > @{Name=VMware Tools; Version=3.1.1.3705} > > @{Name=MSXML 6 Service Pack 2 (KB954459); Version=6.20.1099.0} > > @{Name=Microsoft .NET Framework 3.0 Service Pack 1; Version=3.1.21022} > > @{Name=Microsoft .NET Framework 2.0 Service Pack 1; Version=2.1.21022} > > @{Name=Quarantine Server; Version=3.5.0} > > @{Name=Reporting Server (Symantec Corporation); Version=1.0.197.0} > > @{Name=CorpServerTuner; Version=6.0} > > @{Name=Windows Rights Management Client Backwards Compatibility SP2; > > Version=5.2.70} > > @{Name=Microsoft SQL Server Desktop Engine; Version=8.00.2039} > > @{Name=Windows Presentation Foundation; Version=3.0.6920.0} > > > > How do I get rid of the @{} stuff. I would just like to show the name of > > the software and the version number. > > > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: writing output to log file from gwmi You can also append - just use -NoClobber switch parameter and it won't overwrite your file Martin "RG" <RG@newsgroup> wrote in message news:34B355C8-F521-4B39-ADE3-30B28C8FEF3F@newsgroup Quote: > You can't append informaton to a file using Export-Csv correct? I have a > bunch of other information that I'm collecting in the script that is being > placed into the file and I didn't see how I could use the Export-Csv since > this isn't a one-line type of script. > > "RichS [MVP]" wrote: > Quote: >> You could try this >> >> >> Get-WmiObject -Class Win32_Product | Select Name, version | Export-Csv >> sw.txt -NoTypeInformation >> Import-Csv sw.txt >> >> Change the file names to yours >> >> -- >> Richard Siddaway >> All scripts are supplied "as is" and with no warranty >> PowerShell MVP >> Blog: http://richardsiddaway.spaces.live.com/ >> PowerShell User Group: http://www.get-psuguk.org.uk >> >> >> "RG" wrote: >> Quote: >> > I'm trying to output the results from the following powershell script >> > to a >> > log file: >> > >> > $strComputer = Read-Host "Enter Machine name" >> > $strDate = Get-Date -Format M.d.yyyy >> > $csvFilePath = 'C:\' >> > $strLog = New-Item -ItemType file >> > $csvFilePath\$strComputer-$strDate.log >> > -Force >> > $software = gwmi -Namespace root\CIMV2 -Class >> > Win32_Product -ComputerName >> > $strComputer | Select Name, Version >> > Add-Content $strLog $software >> > What it places in the log file is the following : >> > >> > @{Name=VMware Tools; Version=3.1.1.3705} >> > @{Name=MSXML 6 Service Pack 2 (KB954459); Version=6.20.1099.0} >> > @{Name=Microsoft .NET Framework 3.0 Service Pack 1; Version=3.1.21022} >> > @{Name=Microsoft .NET Framework 2.0 Service Pack 1; Version=2.1.21022} >> > @{Name=Quarantine Server; Version=3.5.0} >> > @{Name=Reporting Server (Symantec Corporation); Version=1.0.197.0} >> > @{Name=CorpServerTuner; Version=6.0} >> > @{Name=Windows Rights Management Client Backwards Compatibility SP2; >> > Version=5.2.70} >> > @{Name=Microsoft SQL Server Desktop Engine; Version=8.00.2039} >> > @{Name=Windows Presentation Foundation; Version=3.0.6920.0} >> > >> > How do I get rid of the @{} stuff. I would just like to show the name >> > of >> > the software and the version number. >> > >> > |
My System Specs![]() |
| | #5 (permalink) |
| | RE: writing output to log file from gwmi OK then this will work $data = Get-WmiObject -Class Win32_Product | Select Name, version | out-string add-content sw.txt $data but some of the long names will be truncated if you want the full name could try something like this Get-WmiObject -Class Win32_Product | Select Name, version | foreach { $data = "{0},{1}" -f $($_.Name), $($_.version) Add-Content sw.txt $data } -- Richard Siddaway All scripts are supplied "as is" and with no warranty PowerShell MVP Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "RG" wrote: Quote: > You can't append informaton to a file using Export-Csv correct? I have a > bunch of other information that I'm collecting in the script that is being > placed into the file and I didn't see how I could use the Export-Csv since > this isn't a one-line type of script. > > "RichS [MVP]" wrote: > Quote: > > You could try this > > > > > > Get-WmiObject -Class Win32_Product | Select Name, version | Export-Csv > > sw.txt -NoTypeInformation > > Import-Csv sw.txt > > > > Change the file names to yours > > > > -- > > Richard Siddaway > > All scripts are supplied "as is" and with no warranty > > PowerShell MVP > > Blog: http://richardsiddaway.spaces.live.com/ > > PowerShell User Group: http://www.get-psuguk.org.uk > > > > > > "RG" wrote: > > Quote: > > > I'm trying to output the results from the following powershell script to a > > > log file: > > > > > > $strComputer = Read-Host "Enter Machine name" > > > $strDate = Get-Date -Format M.d.yyyy > > > $csvFilePath = 'C:\' > > > $strLog = New-Item -ItemType file $csvFilePath\$strComputer-$strDate.log > > > -Force > > > $software = gwmi -Namespace root\CIMV2 -Class Win32_Product -ComputerName > > > $strComputer | Select Name, Version > > > Add-Content $strLog $software > > > What it places in the log file is the following : > > > > > > @{Name=VMware Tools; Version=3.1.1.3705} > > > @{Name=MSXML 6 Service Pack 2 (KB954459); Version=6.20.1099.0} > > > @{Name=Microsoft .NET Framework 3.0 Service Pack 1; Version=3.1.21022} > > > @{Name=Microsoft .NET Framework 2.0 Service Pack 1; Version=2.1.21022} > > > @{Name=Quarantine Server; Version=3.5.0} > > > @{Name=Reporting Server (Symantec Corporation); Version=1.0.197.0} > > > @{Name=CorpServerTuner; Version=6.0} > > > @{Name=Windows Rights Management Client Backwards Compatibility SP2; > > > Version=5.2.70} > > > @{Name=Microsoft SQL Server Desktop Engine; Version=8.00.2039} > > > @{Name=Windows Presentation Foundation; Version=3.0.6920.0} > > > > > > How do I get rid of the @{} stuff. I would just like to show the name of > > > the software and the version number. > > > > > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Writing a formatted directory output to file | PowerShell | |||
| Writing File to CD ROM | VB Script | |||
| Re: Writing output to a formatted file | PowerShell | |||
| writing output to XML file | PowerShell | |||
| Writing to host in functions and cmdlets - how to capture this output | PowerShell | |||