Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - writing output to log file from gwmi

Reply
 
Old 3 Weeks Ago   #1 (permalink)
RG


 
 

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 SpecsSystem Spec
Old 3 Weeks Ago   #2 (permalink)
RichS [MVP]


 
 

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 SpecsSystem Spec
Old 3 Weeks Ago   #3 (permalink)
RG


 
 

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 SpecsSystem Spec
Old 3 Weeks Ago   #4 (permalink)
Martin Zugec


 
 

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 SpecsSystem Spec
Old 3 Weeks Ago   #5 (permalink)
RichS [MVP]


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46