Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome 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. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - how to get "select @@version" to display one long string

Reply
 
Old 08-07-2007   #1 (permalink)
Frank


 
 

how to get "select @@version" to display one long string

Hi,

I have a script which gets the SQLServer version but it comes back with a
string and 3 linefeeds. Can someone help me put this into one long string?
Here is the script:

$conn = new-object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "server=testsvr;integrated
security=sspi;database=master"
$conn.Open()
$cmd = new-object System.Data.SqlClient.SqlCommand
$cmd.CommandText="SELECT @@VERSION as version"

$cmd.Connection=$conn
$rdr = $cmd.ExecuteReader()

While($rdr.Read()){
Write-Host "version: $($rdr['version'])"
}

Output:

version: Microsoft SQL Server 2005 - 9.00.3054.00 (Intel X86)
Mar 23 2007 16:28:52
Copyright (c) 1988-2005 Microsoft Corporation
Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)

My System SpecsSystem Spec
Old 08-07-2007   #2 (permalink)
Jeremiah Buckley


 
 

RE: how to get "select @@version" to display one long string

There's probably a better way to do this, but at the end of the script you
could do:

# instead of Write-Host, just capture the result
While($rdr.Read()){
$verionsString = "version: $($rdr['version'])"
}
# and
# replace newlines and then replace extra spaces
$versionString -replace "`n"," " -replace "[\s][\s]*"," "



"Frank" wrote:

> Hi,
>
> I have a script which gets the SQLServer version but it comes back with a
> string and 3 linefeeds. Can someone help me put this into one long string?
> Here is the script:
>
> $conn = new-object System.Data.SqlClient.SqlConnection
> $conn.ConnectionString = "server=testsvr;integrated
> security=sspi;database=master"
> $conn.Open()
> $cmd = new-object System.Data.SqlClient.SqlCommand
> $cmd.CommandText="SELECT @@VERSION as version"
>
> $cmd.Connection=$conn
> $rdr = $cmd.ExecuteReader()
>
> While($rdr.Read()){
> Write-Host "version: $($rdr['version'])"
> }
>
> Output:
>
> version: Microsoft SQL Server 2005 - 9.00.3054.00 (Intel X86)
> Mar 23 2007 16:28:52
> Copyright (c) 1988-2005 Microsoft Corporation
> Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
wscript.echo only a new line / embed a "CR" in a text string ? VB Script
do not display "ERRORS" when running script without using $erroractionpreference = "SilentlyContinue" PowerShell
"select Name,Path from Win32_Share" permissions required by ASP.NET to return paths, Vista security
"string STR_ERR_OS was not found in string table" Vista installation & setup
Windows Vista "international" or "North America" version?! Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46