Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

output .ps1 script to text file

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 07-11-2007   #1 (permalink)
Aaron
Guest


 

output .ps1 script to text file

I have the following script that list installed hotfixes. My problem is right
now it uses the write-host to show it on screen. I am looking for assistance
on how it can be modified to either write to screen and text file or just a
text file.

$strComputer = "."

$colItems = get-wmiobject -class "Win32_QuickFixEngineering" -namespace
"root\CIMV2" `
-computername $strComputer

foreach ($objItem in $colItems) {
write-host "Caption: " $objItem.Caption | Out-File "D:\scripts\test.txt"
write-host "CS Name: " $objItem.CSName
write-host "Description: " $objItem.Description
write-host "Fix Comments: " $objItem.FixComments
write-host "HotFix ID: " $objItem.HotFixID
write-host "InstallationDate: " $objItem.InstallDate
write-host "Installed By: " $objItem.InstalledBy
write-host "Installed On: " $objItem.InstalledOn
write-host "Name: " $objItem.Name
write-host "Service Pack In Effect: " $objItem.ServicePackInEffect
write-host "Status: " $objItem.Status
write-host
}

My System SpecsSystem Spec
Old 07-11-2007   #2 (permalink)
Nigel Sharples
Guest


 

Re: output .ps1 script to text file

You could write to the screen and file by using tee-object like this:

$colItems | select-object CSName, Description, FixComments, HotFixID,
InstallDate, InstalledBy, InstalledOn, Name, ServicePackInEffect, Status |
tee-object outfile.txt

Get rid of tee-object and it will just write to the screen.

--
Nigel Sharples [MSFT]
Windows PowerShell
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.


"Aaron" <Aaron@discussions.microsoft.com> wrote in message
news:118C1725-1C07-44B3-B935-D31A1B0F1C47@microsoft.com...
>I have the following script that list installed hotfixes. My problem is
>right
> now it uses the write-host to show it on screen. I am looking for
> assistance
> on how it can be modified to either write to screen and text file or just
> a
> text file.
>
> $strComputer = "."
>
> $colItems = get-wmiobject -class "Win32_QuickFixEngineering" -namespace
> "root\CIMV2" `
> -computername $strComputer
>
> foreach ($objItem in $colItems) {
> write-host "Caption: " $objItem.Caption | Out-File
> "D:\scripts\test.txt"
> write-host "CS Name: " $objItem.CSName
> write-host "Description: " $objItem.Description
> write-host "Fix Comments: " $objItem.FixComments
> write-host "HotFix ID: " $objItem.HotFixID
> write-host "InstallationDate: " $objItem.InstallDate
> write-host "Installed By: " $objItem.InstalledBy
> write-host "Installed On: " $objItem.InstalledOn
> write-host "Name: " $objItem.Name
> write-host "Service Pack In Effect: " $objItem.ServicePackInEffect
> write-host "Status: " $objItem.Status
> write-host
> }


My System SpecsSystem Spec
Old 07-11-2007   #3 (permalink)
Brandon Shell
Guest


 

Re: output .ps1 script to text file

Try this. It basically puts your info in a string and then sends to just log
if you set $logonly to $true else it sends to log and console.

===== CODE =====

$strComputer = "."
$log = "c:\tools\test.log"
$logonly=$false

"Starting Script" | out-File $log -enc ASCII

$colItems = get-wmiobject -class "Win32_QuickFixEngineering" -namespace
"root\CIMV2" -computername $strComputer

foreach ($objItem in $colItems) {
$msg = "
Caption: $($objItem.Caption)
CS Name: $($objItem.CSName)
Description: $($objItem.Description)
Fix Comments: $($objItem.FixComments)
HotFix ID: $($objItem.HotFixID)
InstallationDate: $($objItem.InstallDate)
Installed By: $($objItem.InstalledBy)
Installed On: $($objItem.InstalledOn)
Name: $($objItem.Name)
Service Pack In Effect: $($objItem.ServicePackInEffect)
Status: $($objItem.Status)
"
if($logOnly)
{
$msg | out-File $log -append -encoding ASCII
}
else
{
$msg | out-File $log -append -encoding ASCII
$msg
}
}
=============================
"Aaron" <Aaron@discussions.microsoft.com> wrote in message
news:118C1725-1C07-44B3-B935-D31A1B0F1C47@microsoft.com...
>I have the following script that list installed hotfixes. My problem is
>right
> now it uses the write-host to show it on screen. I am looking for
> assistance
> on how it can be modified to either write to screen and text file or just
> a
> text file.
>
> $strComputer = "."
>
> $colItems = get-wmiobject -class "Win32_QuickFixEngineering" -namespace
> "root\CIMV2" `
> -computername $strComputer
>
> foreach ($objItem in $colItems) {
> write-host "Caption: " $objItem.Caption | Out-File
> "D:\scripts\test.txt"
> write-host "CS Name: " $objItem.CSName
> write-host "Description: " $objItem.Description
> write-host "Fix Comments: " $objItem.FixComments
> write-host "HotFix ID: " $objItem.HotFixID
> write-host "InstallationDate: " $objItem.InstallDate
> write-host "Installed By: " $objItem.InstalledBy
> write-host "Installed On: " $objItem.InstalledOn
> write-host "Name: " $objItem.Name
> write-host "Service Pack In Effect: " $objItem.ServicePackInEffect
> write-host "Status: " $objItem.Status
> write-host
> }


My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to display screen output to text file in PowerShell Vinod K PowerShell 5 08-08-2008 10:34 PM
Output all content of text file in different columns Jason1008 PowerShell 3 06-04-2008 12:16 AM
Newbie - Output to a text file problem. Kryten PowerShell 9 10-11-2007 04:46 PM
How to insert text at top of xml output Donald Adams PowerShell 4 01-29-2007 02:12 AM
Reccording DOS output to a text file =?Utf-8?B?c2VucmFiZGV0?= Vista security 3 08-10-2006 07:15 AM


Vistax64.com 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 2005-2008

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 47 48 49 50 51