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 - Storedprocedure Parameter from Host

Reply
 
Old 02-14-2008   #1 (permalink)
Gregor


 
 

Storedprocedure Parameter from Host

Hello

I would like set HostName as Parameter
When I gife as cleartext, then is ok. show <<<< OK

I would like automatic from lokal host? How do that?

Thanks
Gregor

$strServer = "."
$HostName = get-WmiObject -class "Win32_ComputerSystem" -namespace
"root\CIMV2" -computername $strServer | select DNSHostName

#SQL Connection create
$conn = new-object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "server=..xxx"
$cmd = new-object System.Data.SqlClient.SqlCommand("spCreateQueue", $conn)
$cmd.CommandType = [System.Data.CommandType]'StoredProcedure'
#$cmd.Parameters.Add("@PrintServerName","hsb990te") <<<< This
linke is OK
$cmd.Parameters.Add("@PrintServerName",""+$HostName) <<<< No
OK???????
$cmd.Connection = $conn
$adapter = new-object System.Data.SqlClient.SqlDataAdapter
$adapter.SelectCommand = $cmd
$ds = new-object System.Data.DataSet
$adapter.Fill($ds)
$conn.close()

#DataTable create
$dt = new-object "System.Data.DataTable" "dtData"
$dt = $ds.Tables[0]
#View
$dt | FOREACH-OBJECT { " " + $_.QueueName + ": " + $_.QueueTemplate + ": " +
$_.QueueRegFile + ": " + $_.PrinterType + ": " + $_.location + ": " +
$_.PrintServer + ": " + $_.PrintServerShort}


My System SpecsSystem Spec
Old 02-14-2008   #2 (permalink)
Shay Levi


 
 

Re: Storedprocedure Parameter from Host


You can get the local computer name via the environment psdrive:

$env:COMPUTERNAME



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Hello
>
> I would like set HostName as Parameter
> When I gife as cleartext, then is ok. show <<<< OK
> I would like automatic from lokal host? How do that?
>
> Thanks
> Gregor
> $strServer = "."
> $HostName = get-WmiObject -class "Win32_ComputerSystem" -namespace
> "root\CIMV2" -computername $strServer | select DNSHostName
> #SQL Connection create
> $conn = new-object System.Data.SqlClient.SqlConnection
> $conn.ConnectionString = "server=..xxx"
> $cmd = new-object System.Data.SqlClient.SqlCommand("spCreateQueue",
> $conn)
> $cmd.CommandType = [System.Data.CommandType]'StoredProcedure'
> #$cmd.Parameters.Add("@PrintServerName","hsb990te") <<<<
> This
> linke is OK
> $cmd.Parameters.Add("@PrintServerName",""+$HostName) <<<< No
> OK???????
> $cmd.Connection = $conn
> $adapter = new-object System.Data.SqlClient.SqlDataAdapter
> $adapter.SelectCommand = $cmd
> $ds = new-object System.Data.DataSet
> $adapter.Fill($ds)
> $conn.close()
> #DataTable create
> $dt = new-object "System.Data.DataTable" "dtData"
> $dt = $ds.Tables[0]
> #View
> $dt | FOREACH-OBJECT { " " + $_.QueueName + ": " + $_.QueueTemplate +
> ": " +
> $_.QueueRegFile + ": " + $_.PrinterType + ": " + $_.location + ": " +
> $_.PrintServer + ": " + $_.PrintServerShort}

My System SpecsSystem Spec
Old 02-14-2008   #3 (permalink)
Gregor


 
 

Re: Storedprocedure Parameter from Host

Thanks for you help - its now ok :-)

Gregor


"Shay Levi" <no@xxxxxx> wrote in message
news:8766a9441f2c18ca3d18c8056162@xxxxxx
Quote:

>
> You can get the local computer name via the environment psdrive:
>
> $env:COMPUTERNAME
>
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

>> Hello
>>
>> I would like set HostName as Parameter
>> When I gife as cleartext, then is ok. show <<<< OK
>> I would like automatic from lokal host? How do that?
>>
>> Thanks
>> Gregor
>> $strServer = "."
>> $HostName = get-WmiObject -class "Win32_ComputerSystem" -namespace
>> "root\CIMV2" -computername $strServer | select DNSHostName
>> #SQL Connection create
>> $conn = new-object System.Data.SqlClient.SqlConnection
>> $conn.ConnectionString = "server=..xxx"
>> $cmd = new-object System.Data.SqlClient.SqlCommand("spCreateQueue",
>> $conn)
>> $cmd.CommandType = [System.Data.CommandType]'StoredProcedure'
>> #$cmd.Parameters.Add("@PrintServerName","hsb990te") <<<<
>> This
>> linke is OK
>> $cmd.Parameters.Add("@PrintServerName",""+$HostName) <<<< No
>> OK???????
>> $cmd.Connection = $conn
>> $adapter = new-object System.Data.SqlClient.SqlDataAdapter
>> $adapter.SelectCommand = $cmd
>> $ds = new-object System.Data.DataSet
>> $adapter.Fill($ds)
>> $conn.close()
>> #DataTable create
>> $dt = new-object "System.Data.DataTable" "dtData"
>> $dt = $ds.Tables[0]
>> #View
>> $dt | FOREACH-OBJECT { " " + $_.QueueName + ": " + $_.QueueTemplate +
>> ": " +
>> $_.QueueRegFile + ": " + $_.PrinterType + ": " + $_.location + ": " +
>> $_.PrintServer + ": " + $_.PrintServerShort}
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: Hiding the Host OS when startng MS VPC with host Virtual PC
Using multiple Parameter sets for a Parameter PowerShell
VirtualPC VM created in XP host hangs in Vista host Virtual PC
How to best control parameter attributes and parameter parsing in your own scripts? PowerShell
Read-Host issue, won't store to variable when using multiple read-host lines PowerShell


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