Write-host in a function, no newline

  • Follow


I'm trying to create a very basic function

function SQLquery ([string]$SQLserver,[string]$SQLCatalog,[string]
$SQLQuery)
{
write-host -fore yellow $SQLserver;
write-host -fore red $SQLCatalog;
write-host -fore cyan $SQLQuery;
write-host "test"
write-host "test2"
write-host "test3"
}
SQLquery('a','b','c')

the output is

a b c(everything in yellow)
blank line
blank line
test
test2
test3

I was expecting:

a (yellow)
b in red
c in cyan
test
test2
test3

What is going on ?
0
Reply Personne 3/19/2010 10:21:28 PM

My mistake.

SQLquery('a','b','c')  needs to be SQLquery 'a' 'b' 'c'
no parentheses, no comma
0
Reply Personne 3/19/2010 10:27:58 PM


You need to use spaces instead of commas as the argument separator

   SQLquery('a' 'b' 'c')

It's something yo just have to get used to.

With commas you were sending the function a single argument whose value was an 
array containing three strings.

  - Larry

Personne wrote:
> I'm trying to create a very basic function
> 
> function SQLquery ([string]$SQLserver,[string]$SQLCatalog,[string]
> $SQLQuery)
> {
> write-host -fore yellow $SQLserver;
> write-host -fore red $SQLCatalog;
> write-host -fore cyan $SQLQuery;
> write-host "test"
> write-host "test2"
> write-host "test3"
> }
> SQLquery('a','b','c')
> 
> the output is
> 
> a b c(everything in yellow)
> blank line
> blank line
> test
> test2
> test3
> 
> I was expecting:
> 
> a (yellow)
> b in red
> c in cyan
> test
> test2
> test3
> 
> What is going on ?
0
Reply Larry__Weiss 3/19/2010 10:37:12 PM

2 Replies
783 Views

(page loaded in 0.04 seconds)

Similiar Articles:
















7/27/2012 6:03:16 PM


Reply: