![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 | Arrays I need to access array members. Based on what I read, I thought this would work but no dice. "Index operation failed; the array index evaluated to null." What am I doing wrong? $Events =Get-EventLog Application -newest 2 $Events[$Events.eventid] |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Arrays "Jason Massie" <jason**R3move**@statisticsio.com> wrote in message news:e%23MeUMUtIHA.2068@xxxxxx
Your first line retrieves the last 2 entries in the application log, and the next line.. well.. I'm not sure what you're trying to do there. Perhaps this is what you're after, which shows the eventid for each of the 2 array members .... $Events =Get-EventLog Application -newest 2 $events | foreach {$_.EventID} -- Jon | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Arrays I am trying to reference the columns in a SQL 2008 invoke-sqlcmd command. I tried with your syntax but it looks like it is treating $_.* as literals. $Events =Get-EventLog Application -newest 2 ForEach-Object {invoke-sqlcmd -query "insert into AppLogger([time], [type], [source],[eventid], [message]) values ($_.time, $_.type, $_.source,$_.eventid, $_.message)" -ServerInstance LocalHost} I get: Invoke-Sqlcmd : The multi-part identifier ".time" could not be bound. The multi-part identifier ".type" could not be bound. The multi-part identifier ".source" could not be bound. The multi-part identifier ".eventid" could not be bound. The multi-part identifier ".message" could not be bound. "Jon" <Email_Address@xxxxxx> wrote in message news:u7j37SUtIHA.4560@xxxxxx
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||
| Guest | Re: Arrays "Jason Massie" <jason**R3move**@statisticsio.com> wrote in message news:%23BAf2aUtIHA.4924@xxxxxx
Well you're the piping '|' in there, by the looks of it. Perhaps try it with $Events | ForEach-Object {invoke-sqlcmd ......... -- Jon | ||||||||||||
My System Specs![]() | |||||||||||||
| | #5 (permalink) | ||||||||||||
| Guest | Re: Arrays "Jon" <Email_Address@xxxxxx> wrote in message news:ejb3xmUtIHA.1436@xxxxxx
The 'missing' was missing. Should have read "Well you're missing the piping '|' in there, by the looks of it..." -- Jon | ||||||||||||
My System Specs![]() | |||||||||||||
| | #6 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Arrays I think I am getting close. It is like it is trying to insert the full path to the "column" name instead of the value. $Events = Get-EventLog Application -newest 1 $Events | foreach-object {invoke-sqlcmd -query "insert into AppLogger([source]) values ($events.source)" -ServerInstance LocalHost} It returns: Invoke-Sqlcmd : The multi-part identifier "System.Diagnostics.EventLogEntry.source" could not be bound. Any other ideas? "Jon" <Email_Address@xxxxxx> wrote in message news:%23l18joUtIHA.548@xxxxxx
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #7 (permalink) | ||||||||||||
| Guest | Re: Arrays Hmm, this inserts the right value(MSSQLSERVER) but it is really not the logic that I want. $Events = Get-EventLog Application -newest 1 $source = $events.source $Events | foreach-object {invoke-sqlcmd -query "insert into demodb..AppLogger([source]) values ('$source')" -ServerInstance LocalHost} This executes but it inserts this value: 'System.Diagnostics.EventLogEntry.source' $Events = Get-EventLog Application -newest 1 $Events | foreach-object {invoke-sqlcmd -query "insert into demodb..AppLogger([source]) values ('$events.source')" -ServerInstance LocalHost} What am I missing? Thanks. "Jason Massie" <jason**R3move**@statisticsio.com> wrote in message news:e%23MeUMUtIHA.2068@xxxxxx
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #8 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Arrays two things. 1) when you put a variable in a string and you want to access a property. You need to wrap in $() so powershell knows to unwrap it 2) I dont really think this is what you expect. $Events is an collection of Events. If you do $Events.Source it implies that $Events is an element in the collection which is not. When you pipe a collection through foreach-object you can reference the current element by using $_. Try this $Events = Get-EventLog Application -newest 1 $Events | foreach-object {invoke-sqlcmd -query "insert into demodb..AppLogger([source]) values ($_.source)" -ServerInstance LocalHost} "jason" <jason-r3move@xxxxxx> wrote in message news:7DA87571-E9B8-4098-BB36-9109C9947D96@xxxxxx
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #9 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Arrays It took a little tweak. Powershell in SQL 2008 is really cool. Where should a powershell newbie get a crash course? $Events = Get-EventLog Application -newest 100 $Events | foreach-object {invoke-sqlcmd -query "insert into demodb..AppLogger([source]) values ('$($_.source)')" -ServerInstance LocalHost} "Brandon [MVP]" <tshell.mask@xxxxxx> wrote in message news:CE48DB89-27E0-4AAC-8FFA-09F19037239E@xxxxxx
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #10 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Arrays Bruce Payette's book is a good start. To get a feel for it, though, the best thing I've found is to just use it, and check the docs installed with PowerShell - they cover a _bunch_ of the core of the language, including useful examples for some scenarios. And post questions. Live people can always give a tailor-made crash course. : ) "jason" <jason-r3move@xxxxxx> wrote in message news:F9AB82D3-9505-4C3B-925F-7FD4D0AD0C18@xxxxxx
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Overwriting Arrays | DavidLMeissner | PowerShell | 1 | 12-27-2007 07:33 PM |
| Arrays in Powershell | Daren Daigle | PowerShell | 2 | 12-03-2007 07:37 AM |
| Multidimensional arrays | Jacob Saaby Nielsen | PowerShell | 6 | 11-27-2007 10:44 AM |
| Working with arrays | Jobbsy | PowerShell | 6 | 11-19-2007 05:15 AM |
| Bug with multidimensional arrays | IJuan | PowerShell | 1 | 04-22-2007 02:24 PM |