![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 | Newbie - Writing to host and a text file I would like to list some information about services and write the information to the console and to a file. Here's my script and a few questions: $strComputer = "server1" Get-WmiObject win32_service -ComputerName $strComputer | Select-Object Name,State,StartMode,StartName | Out-File $strComputer+"_services.txt" 1. How do I write it to the console as well? When I try Write-Host it returns unformated text, so don't think that's appropriate here. 2. How do I concatenate the filename so it's "server1_services.txt". It seems to ignore the + operator. Thanks |
| | #2 (permalink) |
| Guest | Re: Newbie - Writing to host and a text file $strComputer = "server1" gwmi -q "select * from win32_service" -ComputerName $strComputer | Select Name,State,StartMode,StartName | tee-object "$strComputer_services.txt" -- $hay http://scriptolog.blogspot.com "FreddieF" <FreddieF@discussions.microsoft.com> wrote in message news:8D7F6E14-3FB5-4AEA-8F9F-9EDA407C687A@microsoft.com... >I would like to list some information about services and write the > information to the console and to a file. Here's my script and a few > questions: > > $strComputer = "server1" > Get-WmiObject win32_service -ComputerName $strComputer | > Select-Object Name,State,StartMode,StartName | > Out-File $strComputer+"_services.txt" > > 1. How do I write it to the console as well? When I try Write-Host it > returns unformated text, so don't think that's appropriate here. > 2. How do I concatenate the filename so it's "server1_services.txt". It > seems to ignore the + operator. > > Thanks > |
| | #3 (permalink) |
| Guest | Re: Newbie - Writing to host and a text file On Thu, 15 Feb 2007 11:38:07 -0800, FreddieF wrote: > I would like to list some information about services and write the > information to the console and to a file. Here's my script and a few > questions: > > $strComputer = "server1" > Get-WmiObject win32_service -ComputerName $strComputer | > Select-Object Name,State,StartMode,StartName | > Out-File $strComputer+"_services.txt" > > 1. How do I write it to the console as well? When I try Write-Host it > returns unformated text, so don't think that's appropriate here. > 2. How do I concatenate the filename so it's "server1_services.txt". It > seems to ignore the + operator. > > Thanks Instead of Out-File, Use Tee-Object $strComputer = "server1" Get-WmiObject win32_service -ComputerName $strComputer | Select-Object Name,State,StartMode,StartName | Tee-object $strComputer+"_services.txt" -- Jeffery Hicks SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com VBScript & Windows PowerShell Training - www.ScriptingTraining.com/classes.asp Windows PowerShell? - www.SAPIENPress.com/powershell.asp blog: http://blog.SAPIEN.com blog: http://jdhitsolutions.blogspot.com |
| | #4 (permalink) |
| Guest | Re: Newbie - Writing to host and a text file Thanks. I still can't work out how to use the + operator to create the file name server1_services.txt? With VBscript you would just use strComputer & "_services.txt" "Jeffery Hicks" <"jhicks[at]SAPIEN.com" wrote: > On Thu, 15 Feb 2007 11:38:07 -0800, FreddieF wrote: > > > I would like to list some information about services and write the > > information to the console and to a file. Here's my script and a few > > questions: > > > > $strComputer = "server1" > > Get-WmiObject win32_service -ComputerName $strComputer | > > Select-Object Name,State,StartMode,StartName | > > Out-File $strComputer+"_services.txt" > > > > 1. How do I write it to the console as well? When I try Write-Host it > > returns unformated text, so don't think that's appropriate here. > > 2. How do I concatenate the filename so it's "server1_services.txt". It > > seems to ignore the + operator. > > > > Thanks > > Instead of Out-File, Use Tee-Object > > $strComputer = "server1" > Get-WmiObject win32_service -ComputerName $strComputer | > Select-Object Name,State,StartMode,StartName | > Tee-object $strComputer+"_services.txt" > > -- > Jeffery Hicks > SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com > VBScript & Windows PowerShell Training - > www.ScriptingTraining.com/classes.asp > Windows PowerShell? - www.SAPIENPress.com/powershell.asp > > blog: http://blog.SAPIEN.com > blog: http://jdhitsolutions.blogspot.com > |
| | #5 (permalink) |
| Guest | Re: Newbie - Writing to host and a text file On Thu, 15 Feb 2007 13:07:10 -0800, FreddieF wrote: > Thanks. > > I still can't work out how to use the + operator to create the file name > server1_services.txt? With VBscript you would just use > strComputer & "_services.txt" > > "Jeffery Hicks" <"jhicks[at]SAPIEN.com" wrote: > >> On Thu, 15 Feb 2007 11:38:07 -0800, FreddieF wrote: >> >>> I would like to list some information about services and write the >>> information to the console and to a file. Here's my script and a few >>> questions: >>> >>> $strComputer = "server1" >>> Get-WmiObject win32_service -ComputerName $strComputer | >>> Select-Object Name,State,StartMode,StartName | >>> Out-File $strComputer+"_services.txt" >>> >>> 1. How do I write it to the console as well? When I try Write-Host it >>> returns unformated text, so don't think that's appropriate here. >>> 2. How do I concatenate the filename so it's "server1_services.txt". It >>> seems to ignore the + operator. >>> >>> Thanks >> >> Instead of Out-File, Use Tee-Object >> >> $strComputer = "server1" >> Get-WmiObject win32_service -ComputerName $strComputer | >> Select-Object Name,State,StartMode,StartName | >> Tee-object $strComputer+"_services.txt" >> >> -- >> Jeffery Hicks >> SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com >> VBScript & Windows PowerShell Training - >> www.ScriptingTraining.com/classes.asp >> Windows PowerShell? - www.SAPIENPress.com/powershell.asp >> >> blog: http://blog.SAPIEN.com >> blog: http://jdhitsolutions.blogspot.com >> You don't need anything really $strComputer_services.txt but the problem is the _ character. Try $strComputer-services.txt and see if that works better. -- Jeffery Hicks SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com VBScript & Windows PowerShell Training - www.ScriptingTraining.com/classes.asp Windows PowerShell? - www.SAPIENPress.com/powershell.asp blog: http://blog.SAPIEN.com blog: http://jdhitsolutions.blogspot.com |
| | #6 (permalink) |
| Guest | Re: Newbie - Writing to host and a text file > You don't need anything really > $strComputer_services.txt > but the problem is the _ character. Try > $strComputer-services.txt > > and see if that works better. An alternative is: out-file "${strComputer}_services.txt" "Jeffery Hicks" <"jhicks[at]SAPIEN.com"> wrote in message news:r5kjwtlulzjh.1q5ymj0ek9j3t$.dlg@40tude.net... > On Thu, 15 Feb 2007 13:07:10 -0800, FreddieF wrote: > >> Thanks. >> >> I still can't work out how to use the + operator to create the file name >> server1_services.txt? With VBscript you would just use >> strComputer & "_services.txt" >> >> "Jeffery Hicks" <"jhicks[at]SAPIEN.com" wrote: >> >>> On Thu, 15 Feb 2007 11:38:07 -0800, FreddieF wrote: >>> >>>> I would like to list some information about services and write the >>>> information to the console and to a file. Here's my script and a few >>>> questions: >>>> >>>> $strComputer = "server1" >>>> Get-WmiObject win32_service -ComputerName $strComputer | >>>> Select-Object Name,State,StartMode,StartName | >>>> Out-File $strComputer+"_services.txt" >>>> >>>> 1. How do I write it to the console as well? When I try Write-Host it >>>> returns unformated text, so don't think that's appropriate here. >>>> 2. How do I concatenate the filename so it's "server1_services.txt". >>>> It >>>> seems to ignore the + operator. >>>> >>>> Thanks >>> >>> Instead of Out-File, Use Tee-Object >>> >>> $strComputer = "server1" >>> Get-WmiObject win32_service -ComputerName $strComputer | >>> Select-Object Name,State,StartMode,StartName | >>> Tee-object $strComputer+"_services.txt" >>> >>> -- >>> Jeffery Hicks >>> SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com >>> VBScript & Windows PowerShell Training - >>> www.ScriptingTraining.com/classes.asp >>> Windows PowerShell? - www.SAPIENPress.com/powershell.asp >>> >>> blog: http://blog.SAPIEN.com >>> blog: http://jdhitsolutions.blogspot.com >>> > > You don't need anything really > $strComputer_services.txt > but the problem is the _ character. Try > $strComputer-services.txt > > and see if that works better. > -- > Jeffery Hicks > SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com > VBScript & Windows PowerShell Training - > www.ScriptingTraining.com/classes.asp > Windows PowerShell? - www.SAPIENPress.com/powershell.asp > > blog: http://blog.SAPIEN.com > blog: http://jdhitsolutions.blogspot.com |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Howto: Add lines of text from a specific point in a text file.. | Daz | VB Script | 13 | 06-24-2008 10:55 AM |
| writing out to file | Braden C. Roberson-Mailloux | PowerShell | 3 | 05-18-2008 01:12 PM |
| Newbie - Output to a text file problem. | Kryten | PowerShell | 9 | 10-11-2007 04:46 PM |
| How do I read a text file and sort text by fixed positions? | Cornelius | PowerShell | 5 | 07-20-2007 06:34 PM |
| Writing to host in functions and cmdlets - how to capture this output | Keith Hill [MVP] | PowerShell | 1 | 12-30-2006 03:54 PM |