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 - output .ps1 script to text file

Reply
 
Old 07-11-2007   #1 (permalink)
Aaron


 
 

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


 
 

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


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
Re: Send command line via WMI - Pipe output to text file on remote PowerShell
How to display screen output to text file in PowerShell PowerShell
Output all content of text file in different columns PowerShell
Newbie - Output to a text file problem. PowerShell
Reccording DOS output to a text file Vista security


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