![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | 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) |
| | 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) |
| | 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 | |
| |
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 | |||