Display differences Write-Host and Write-Warning

I'm new to PS, and a little embarrassed I can't find the answer to this on 
my own...

I like to format text literals across multiple lines to manage the right 
margin of code text, but I'm having a problem with Write-Warning.  There is 
apparently a significant difference in the way it handles its message text.

Write-Host "Some literal text appended to"        `
                    "some more text on the same line"

Produces the desired output:

Some literal text appended to some more text on the same line

As you, PowerShellers, are aware, the following, similar PS code:

Write-Warning "Some literal text appended to"	`
                           "some more text on the same line"

Generates the error:

A positional parameter cannot be found that accepts argument 'some more text 
on the same line'.
At :line:6 char:13
+ Write-Warning <<<<  "Some literal text appended to"	`

Removing the backtick from the end of the first line eliminates the error, 
but generates the following three lines of output:
WARNING: Some literal text appended to

some more text on the same line

So, how do I get Write-Warning to generate one line output like:
WARNING: Some literal text appended to some more text on the same line

without putting all on one continuous line of script code? 

1/1/2010 6:39:34 PM
windows.powershell 690 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 48

It's not that obvious, don't feel bad :)
The reason is the way the Cmdlet's positional parameters treat values from 
remaining arguments.

Write-Host's first -and only- positional parameter (-Object) takes an 
[Object] as its argument and accepts values from remaining arguments, this 
means you can pass a space delimited array to it (due to the line 
continuation ` used). The Cmdlet will join the array's element with the 
[Object] pass to its -Separator parameter, whose default is set to a blank 
Write-Warning's first -and only- positional parameter (-Message), just like 
Write-Verbose's and Write-Debug's, takes a [String] as argument and does not 
accept values from remaining arguments. That means that you cannot pass more 
than one string unless you concatenate them inside an expression ( ), expand 
the array in a double-quoted subexpression "$( )" or better yet, set the 
message to a variable and pass it to the Cmdlet.

# compare
Get-Help Write-Host -Parameter Object
Get-Help Write-Warning -Parameter Message

#    -    -    -    -    -    -    -    -    -    -    -    -    -    #
# passing a 2-element space-delimited array to Write-Host's -Object
# joined with the Write-Host's default separator
Write-Host "Some literal text appended to" `
                            "some more text on the same line"

# passing a 2-element space-delimited array to Write-Host's -Object
# joined with '_'
Write-Host "Some literal text appended to" `
                            "some more text on the same line" -Sep _

#    -    -    -    -    -    -    -    -    -    -    -    -    -    #
# Here are a few ways to get Write-Warning to generate one line output
# without putting all on one continuous line of script code

# passing an expression that concatenates 3 strings to
# Write-Warning's -Message
Write-Warning ("Some literal text appended to" + " " +
                            "some more text on the same line")

# passing an expression that concatenates 2 strings to
# Write-Warning's -Message. Note the trailing space appended
# to the 1st string
Write-Warning ("Some literal text appended to " +
                             "some more text on the same line")

# passing a double-quoted subexpression that outputs a string-expanded
# 2-element comma-separated array joined with the $OFS
# (Output Field Separator) to Write-Warning's -Message.
# By default the $OFS is set to a blank space
Write-Warning "$("Some literal text appended to",
                            "some more text on the same line")"

# set the message in a variable and pass it to the Cmdlet. Note the
# trailing space appended to the 1st string
$msg = "Some literal text appended to " +
                            "some more text on the same line"
Write-Warning $msg
#    -    -    -    -    -    -    -    -    -    -    -    -    -    #

Hope this clears it up.
Happy 2010!

1/1/2010 8:41:02 PM

Similar Artilces:

Dual Displays
I want to connect my Sharp Aquos flat screen TV to my computer, and see my desktop on both the TV and computer monitor. Windows Vista Home Premium. HP Pavilion a1610n computer. Galaxy GeForce 8400 GS graphics card, outputs: 1-VGA, 1-DVI, and 1-SVGA. There is no HDMI port on the card. I connected a VGA cable between the motherboard "on-board" VGA port and the TV, figuring that I could use that output to work with the TV. The computer monitor is plugged into the GeForce graphics card. Tried the Desktop "Display Setting". It says, the number 2 monitor is "N...

Folder could not be displayed
I am running Windows XP and Outlook Express 6 just fine then one day my husband does something to my computer and his email account won't work. My email is working just fine but in his he cannot open his inbox. It says folder could not be displayed, and when you send and receive it gives you this error message: "An unknown error has occured. Account: 'incoming.verizon.net'. Server:'incoming.verizon.net'.Protocol:POP3, port: 110, Secure(SSL): No, error number: 0x800C013B" If anyone could help me with this I would greatly appreciate it. Thank you T...

Display a message box "this entry is a duplicate"
How can I display a message box on a form if the shipment number is a duplicate? I need a message box to pop up when user attempts to tab out of the field. Thank you. Something like: Private Sub txtShipNum_BeforeUpdate(Cancel As Integer) If DCount("*", "MyTable", "ShipNum = '" & Me.txtShipNum & "'") > 0 Then Msgbox Me.txtShipNum & " already exists." Cancel = True End If End Sub This assumes that your text box is named txtShipNum, that the name of the field in table MyTable is ShipNum...

How to disable auto-capitalization of first letter in Outlook eMail writing?
When I write new eMails in Outlook then always the first letter on new lines is automatically turned into a capital letter. How can I turn this "feature" off? Characters should be taken as I type them. Sven Tools, Options, Spelling tab, Auto Correct, turn it off or change the Auto Correct Options. If Word is your editor, see the instructions for auto correct in Word's Help. "Sven Claasen" wrote: > When I write new eMails in Outlook then always the first letter on new lines > is automatically turned into a capital letter. > > How can I turn this &quo...

how to display values in 3 cells into one cell
Anyone can help me how do I display the 3 separate different values in 3 cells into just one single cell ? thanks so much in advance. Either there was a typo or there's an echo in here. That line should have been: = A1 & " " & B1 & " " & C1 "Bradley Dawson" <bradleydawson@earthlink.net> wrote in message news:l464b.2224$Lk5.2093@newsread3.news.pas.earthlink.net... > In the target cell, type: > > = A1 & B1 & C1 > > where A1, B1, C1 are the cell addresses that you want to concatenate. > > If these have number...

How to select & display distinct values
Hello, I need help with a form please. My form has two controls, the first being a combo box. This box should select the company name from a lookup table. The lookup table has only two companies in it, however, they each are repeated several time. Company 1 has about 10 rows, company 2 has 3 rows. I used the query builder and came up with the statement: "SELECT DISTINCT Lktbl_Role_Master.CompanyName FROM Lktbl_Role_Master;" When I run the statement directly from query view, it executes perfectly and returns exactly two rows (one for each company, in a datasheet view) ho...

Display Time in Outlook
The time setting in my Outlook is one hour behind my actual time. I cannot determine how to change the time. Outlook is the only item that is incorrect. Other display times in operating system are correct. Thanks, Jodi ...

Problem writing to 2nd table w/ 1st table's key
Hi everyone. I'm as new to VBA as you can get. Please bear this in mind when viewing my code. I'm self teaching myself and its not going so well. Anyhow, I was hoping that someone could explain what I'm doing wrong. I'm working on a small checklist program that were using out in the field to perform safety inspections. I set my database up similar to an ordering system in that I have a table named Inspections which I'm storing the building and owner data & another table named DeficiencyDetail where I'm attempting to store each separate deficiency. An inspecti...

PK and FK Displayed
I am a complete Visio newbie, and cannot find the answer I need in books or online help. I am trying to create ER diagrams from scratch, and not connected to real tables, using VEA. I have added tables ('Entities') to the form, connected them with a Relationship connector, and, in the Database Properties window I've assigned the end points to a Primary Key on the left and a Foreign Key on the right. But the model shows the connector as running between the top colums on both sides, whereas I want the keys to be in that upper box and provide the connector's end points. Wh...

Formulas are displayed, results are not
Hello, For some reason, when I enter a formula into a cell and press enter, the formula just stays there. Anyone know what I can do to show the results? I tried pressing Cntrl + `, but that didn't work. FYI, when I cut and paste a column from a separate workbook, that column works like normal (i.e., the formulas produce results). Thanks for any suggestions! Hi Mike, Maybe your cell is preformatted as Text. Try formatting to general then erase your = and type it in again. HTH Martin "Mike C" <js2k111@yahoo.com> wrote in message news:f699bcd4-ad82-4a88-9759-5638c147b...

Putting the resources of different projects togehter in the masterproject
hi, i maintained the resources in individual projects through manuall insertion of each department. The resources arent broken down to collegues, but are on a department level (like 10people form department ZZ) and there is no database behind. Now i wanted to unite these "sub"projects in a masterproject. Therefore, i inserted the individual projects and linked them with the masterproject. At them moment, i am facing the problem, that MSP doesnt sum the hrs of the resources up. EG. NOW: Project Resource Hrs ------------------------------- Sub A ...

Stop displaying a line
I have a line graph/chart and it gets its values using a formula and the values of another column. However this poses a problem because if there is nothing in the targetted column the formula returns 0 cause the line to drop to the bottom, instead of casuing the line to just end until a value is added to the target column. How can I do this? Change your formula to use NA() if the cell is empty. For example: =IF(A1="",NA(),A1) To hide the resulting #N/A errors on the worksheet, you can use conditional formatting. There are instructions here: http://www.contextures.com/xlC...

A question about Console window(display or not display)
I've redirected the (stdin stdout stderr) of a console window process I spawned to a pipe. And I want to display the redirected console window, the question is: If I display it(set Create_new_CONSOLE in createprocess and some flags in startupinfo), I cannot use the redirected way of pipe, which means if i do not display, i can use the pipe communicating with the child process. Does it mean that as long as I disply the console window, windows will change stdin stdout to "screen&keyboard" instead of my pipe? That's right. If you redirect stdin or stdout then you preemp...

unattached textboxes disappear when a msgbox is displayed on a tab control
I'm using Access 2003. I have a form with a tab control on it. I was having problems with labels flashing and I followed the suggesting from Allen Browne - http://allenbrowne.com/ser-46.html. The flashing went away but now when a msgbox is displayed the unattached textboxes that I'm using as labels disappear. They come back as soon as the msgbox is removed from the screen. I've searched google looking for an answer but have come up short. Does anyone know why I'm experiencing this behavior and how to make it go away? Thanks, Rick That *is* strange. Have you tr...

does Excel support multiple display monitors?
Hello All Excel Experts How do I move chart windows to multiple display montors?? (one computer runnng three monitors... Excel Charts will not move off the primary monitor. Your advice is EXTREMELY appreciated thanks. Denni ...

Display or not display series
I have a graph with four series but some of the series may be blank, i.e. the series name is <blank series>. Is there a way to not display these series on the graph and/or legend if they are blank, and display them if they are without deleting the series? Thanks! Clay Create a chart from all the data Select the data on which the chart is based. Choose Data>Filter>AutoFilter In the heading cell for the series name column, select (NonBlanks) from the dropdown list The series with blank name cells will be hidden in the chart. Clay wrote: > I have a graph with four serie...

Displaying an equation
I have an equation setup that is referencing a few other cells that have equations in them. I want to have a cell that displays this equation with the answers that are calculated from these other cells displayed as values in the new equation. Any help would be greatly appreciated. Thanks Check out http://www.mvps.org/dmcritchie/excel/formula.htm#getformula In article <E4143E2B-360A-4B43-955F-73BF8EC60694@microsoft.com>, "hoising8" <hoising8@discussions.microsoft.com> wrote: > I have an equation setup that is referencing a few other cells that have > eq...

Applications of Excel in different industries
I am working on a school project and need different Excel applications used in different industries and if possible names of companies. Thank you. Mary C. I work in the telecom industry. My department uses excel for a whole boat load of different things. From doing equipment pricing/costing, to help with calculations during engineering. One of the common functions that I use it for is to take data from disparate sources and to combine them into a workbook that others can play what-if scenarios. We take data from the AS/400 (MACPAC), mainframe (engineering files), UNIX (dumps of custome...

A general query Im serialising a person object with the following member variables Class Person Private _forenames As String Private _surname As String Private _dob As Date Private _marital_status As MaritalStatus 'Public Get and Set Properties here for each of the above ' I'll not detail them all to save space but Ill show attributes <XmlElementAttribute(Elementname:="forename")> _ <XmlElementAttribute(Elementname:="surname")> _ <XmlElementAttribute(Elementname:="dob"...

How to write a good testimonial
anyone can help... I want to write a good testimonial to a sales person that have help alot during the project "Jassy" <Jassy@discussions.microsoft.com> wrote in message news:6ECEB922-1F40-49B3-86FB-C0B4B8968D2F@microsoft.com... > anyone can help... I want to write a good testimonial to a sales person > that > have help alot during the project I've written a few thank-yous to people who assisted, or to their managers, but I don't have any boilerplate or template for that. You should be as specific as possible, about what that person's contribution...

New Email does not display
When new email arrives you don't know it. You don't know you have new mail until you click on an existing email in your inbox. Any ideas? It's a setting. But... 1. You don't tell us the program you're using. 2. We can't guess if it's Outlook or Outlook Express. 3. This is the Excel newsgroup; you're in the wrong place. :) ******************* ~Anne Troy www.OfficeArticles.com "Travis" <Travis@discussions.microsoft.com> wrote in message news:D864BC01-7D98-48DA-A132-614D02E45963@microsoft.com... > When new email arrives you don't know ...

writing calculated fields
I am trying to avoid starting a Crystal report from scratch, please help me! I need to use the equivalent of the "If, Then, Else" formula in Crystal reports in Report Writer. I need my PO in report writer to: if {IV00101.UOMSCHDL}="xxxxx" then (PO ordered QTY * 30) else if {IV00101.UOMSCHDL}="xxxxx" then (PO ordered QTY * 40) else PO ordered QTY I can only place PO's to the vendor in eaches but I am entering the PO into GP in cases. I have the PO processing side setup correctly, I just need the PO to print now. Thank you! -- CK Create two new calculate...

Display 4 weeks of data
Hello all, I am trying to create a query in which data is displayed for the current month beginning with the first day of the week, first week of the month and ending with the last day of the week, last week of the month. In example: Today is Friday June 1, 2007 but the first day of the week would be Sunday, May 27, 2007. I would like the query to show data between 5/27/2007 through 6/30/2007 -OR- 4/29/2007 through 6/2/2007 for the previous month... Does anyone have any ideas? First day of the current month is DateSerial(Year(Date()), Month(Date()), 1) Last day of the current month...

Dynamic Chart Display
I have set up many dynamic charts using named ranges with the counta function. At times when reopened the data is not displayed properly - it will be skewed to the left with blank intervals although all data is there. It can be corrected by going to the data sheet and resaving the spreadsheet but this is very inconvenient and doesn't always work. This is particularly a problem when the spreadsheet is for distribution or to be used as part of a presentation. Does anyone know if there is a way to 'freeze' the display so this does not occur? Thank you! ...

net display or pole display
We are a small beverage/specialty retailer. We have a requirement to install a customer viewable display. We are using a Pioneer POS that has an available USB and video port. 1. We are thinking of using a small, 7-9" monitor connected to the video port. Can we change the size of the fonts that are used to display pricing? 2. We tried hooking up a flat panel monitor to this port, but it didn't work (even with the net display check boxes activated). I think it is because we did not load drivers for the second monitor. We're a little apprehensive about messing up the touch s...