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: Write-host in a function, no newline - microsoft.public.windows ...I'm trying to create a very basic function function SQLquery ([string]$SQLserver,[string]$SQLCatalog,[string] $SQLQuery) { write-host -fore yell... Display differences Write-Host and Write-Warning - microsoft ...Write-host in a function, no newline - microsoft.public.windows ... Display differences Write-Host and Write-Warning - microsoft ... Write-host in a function, no newline ... Function to Return the IP Address of a known Host - microsoft ...} } Return $regtable } } Function ScanIPs { <# .SYNOPSIS Scans an IP address or subnet of an IP and lists ... Write-host in a function, no newline ... Hash Table not returning properly in Function - microsoft.public ...Write-host in a function, no newline - microsoft.public.windows ... Hash Table not returning properly in Function - microsoft.public ... Write-host in a function, no ... Function Return mangles object? PowerShell/AD - microsoft.public ...Write-host in a function, no newline - microsoft.public.windows ... Function Return mangles object? PowerShell/AD - microsoft.public ... Write-host in a function, no ... Win32_PingStatus (problem resolving hostname / ip adress ...Write-host in a function, no newline - microsoft.public.windows ... Win32_PingStatus (problem resolving hostname / ip adress ... Write-host in a function, no newline ... Hash Table not being returned properly - microsoft.public.windows ...Write-host in a function, no newline - microsoft.public.windows ... Hash Table not returning properly in Function - microsoft.public ... Write-host in a function, no ... [help] using $env - microsoft.public.windows.powershell ...> It won't, it'll read and expand $env:repo, then concatenate that with the rest. Run this to verify: Write-Host "$env:repo\win7\netsetup\scripts" Chris vba line input not recognizing end of line - microsoft.public.vb ...Write-host in a function, no newline - microsoft.public.windows ... vba line input not recognizing end of line - microsoft.public.vb ... Write-host in a function, no ... How to get milliseconds ? - microsoft.public.vb.general.discussion ...... using "Imports VBDT = Microsoft.VisualBasic.DateAndTime", we use the function Timer ... beginning of the process, I write to a log file, and when it's > done, I write to ... Write-host in a function, no newline - microsoft.public.windows ...I'm trying to create a very basic function function SQLquery ([string]$SQLserver,[string]$SQLCatalog,[string] $SQLQuery) { write-host -fore yell... Write-host in a function, no newline - Vista ForumsWelcome 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. NewLine in PoSh - Vista ForumsSimilar topics to: NewLine in PoSh Thread: Forum: Write-host in a function, no newline: PowerShell: How can I set the character that a TextBox may Interpret as NewLine?! PowerShell Scripting Write-Host | PowerShell Pro!There is actually no issue here, the “Write-Host ... Compound this with Functions’ behavior of “returning” all output as a result unless it’s sent to Write-Host ... BSonPoSH » Get-Uptime (fun with Write-Host)I am a BIG fan of Write-Host. Think of Write-Host like wscript.Echo (vbscript) or ... tshell:: Jan.29.2007 :: functions, HowTo, Powershell:: No Comments » 7/27/2012 6:03:16 PM
|