Automating the world one-liner at a time…
Firstly i am sorry to post an unrelated question to this post. However i dont know where to post my questions. Here is my questionSay I have 2 cmdlet'sGet-locationGet-serviceWhen I create a test.ps1 file out of these 2 command and then run it, it will always do a Get-service |fl in the outputIe. A full listing of the second command. Is there a way we can avoid this?
As a general rule, the best place to ask questions is the PowerShell Newsgroup: Microsoft.Public.Windows.PowerShell
What you are seeing with your script is that your script does not PRINT ("OUTPUT to the HOST") the LOCATION and then the SERVICEs. Instead it EMITS them ("WRITES to the OUTPUT STREAM").
Unless you connect things otherwise, the objects on the output stream are sent to some code that will output them to the host AS A COLLECTION. The way that works is that the first object in the collection is used to determine how the rest of the collection will be output. If that code finds something unanticipated in the collection, it just formats it as a list and continues. You can prove this to yourself by doing the following:
PS> gps idle;pwd;gps systemHandles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName------- ------ ----- ----- ----- ------ -- ----------- 0 0 0 28 0 0 IdleDrive : CProvider : Microsoft.PowerShell.Core\FileSystemProviderPath : C:\psPath : C:\ps 664 0 0 16872 20 4 System
What you want to do is:
Get-Location | Out-Host
Get-Service | Out-Host
Jeffrey Snover [MSFT]Windows Management Partner ArchitectVisit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShellVisit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx