![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Executenonquery in pipeline Hi, It's late in the evening here in Norway and I am struggeling with something I believe will be "easy match" for one of you gurus out there. I have one or more ManagementObjects in a variable after collecting diskinfo from the server. I want to insert these into a sql table I have created. $conn = New-Object system.Data.SqlClient.SqlConnection $conn.connectionstring = "Data Source=.;Initial Catalog=dba; Integrated Security=SSPI" $conn.open() $cmd = New-Object System.Data.SqlClient.SqlCommand($conn) $diskinfo=gwmi -computer $server win32_logicaldisk -filter "drivetype=3" What comes next? I have tried different variations of foreach ($disk in $diskinfo) { $insert = "INSERT INTO dbo.diskusage (servername, deviceid, volumename, totalsize, freespace) VALUES (`'$($server.servername)`', `'$($disk.deviceid)`', `'$($disk.volumename)`', $($disk.size),$ ($disk.freespace))" $cmd.executenonquery($insert) } but unlucky so far... Any tips? Thanks, |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Executenonquery in pipeline On Nov 15, 3:23 pm, gurbao <aud...@xxxxxx> wrote:
that here? also, define unlucky: error, no error but no data in db; in short, elaborate! ![]() - Oisin | ||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Executenonquery in pipeline "Oisin Grehan" <oising@xxxxxx> wrote in message news:3a6f1901-8a30-4b5f-ac3f-bba8a71ec488@xxxxxx
accept such large integer values? My disk space size is: 250,056,704,000 That's well over the range of a standard 32-bit int. -- Keith | ||||||||||||||||||||||||
| | #4 (permalink) |
| Guest | Re: Executenonquery in pipeline one thing to note, and i'm sorry it doesn't answer your question.. but the example you made is not using the pipeline, but rather the vbscript like language foreach loop.. if you wanted to use the pipeline you would do something like gwmi -computer $server win32_logicaldisk -filter "drivetype=3" | foreach-object { and something using $_ related to your database stuff } but i know that doesn't answer your problems.. i would just try isolating to see what the problem is, do a simple static insert, see if that works etc.. print something in the loop to see if the loop is even being called etc.. Karl http://www.powershell.com |
| | #5 (permalink) | ||||||||||||
| Guest | Re: Executenonquery in pipeline On Nov 16, 5:40 am, "Karl Prosser[MVP]" <karl@xxxxxx_o_w_e_r_s_h_e_l_l.com> wrote:
To all of you: Thanks for your feedback. Some sleep and a new day was all I needed :-) foreach ($disk in $diskinfo) { $cmd.CommandText = "INSERT INTO dba.dbo.diskusage (servername, deviceid, volumename, totalsize, freespace) VALUES (`'$ ($server.servername)`', `'$($disk.deviceid)`', `'$ ($disk.volumename)`', $($disk.size),$($disk.freespace))" $cmd.executenonquery() | out-null } I use bigint for the disksizes, that should be about (9223372036854775807/1Gb) 8589934592 GB :-) The pipeline-title of this text is misleading, but I started out doing this in the pipeline, but before I got to post this I had changed my mind ;-). Remember; it was laaate last night... Thanks for helping us noobs out, | ||||||||||||
| | #6 (permalink) | ||||||||||||
| Guest | Re: Executenonquery in pipeline "gurbao" <audunj@xxxxxx> wrote in message news:2328fb8f-f3ec-4a05-a1ad-59cc1270beaa@xxxxxx
single quotes within a double quoted string. -- Keith | ||||||||||||
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pipeline and ScriptBlocks | Shane | PowerShell | 8 | 01-21-2008 10:27 PM |
| Brackets in the pipeline | Dmitry Sotnikov | PowerShell | 2 | 09-06-2007 10:33 AM |
| Using the $_ pipeline with WMI | Larry R | PowerShell | 2 | 04-27-2007 09:27 AM |
| pipeline timeout | William Stacey [C# MVP] | PowerShell | 0 | 04-09-2007 03:26 PM |
| A pipeline exercise | Roman Kuzmin | PowerShell | 5 | 10-19-2006 10:56 AM |