![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |
| | #3 (permalink) |
| 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 Specs![]() |
![]() |
| 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 |