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 - Different results from the same -match statement

Reply
 
Old 08-13-2007   #1 (permalink)
Robin Moffatt


 
 

Different results from the same -match statement

Based on this page (http://blogs.technet.com/otto/archive/2007/03/04/
quick-and-dirty-software-inventory-with-psinfo-and-powershell.aspx)
I'm playing around with finding the version of SQL Server running on
different boxes.

Because there are multiple SQL server programs on the install list
returned by psinfo.exe, I'm filtering the output to try and get just
the one with the main version on.

This is an excerpt of the list returned:
Microsoft SQL Server 2005 9.2.3042.00
Microsoft SQL Server 2005
Microsoft SQL Server 2005 Backward compatibility 8.05.2004
Microsoft SQL Server 2005 Integration Services 9.2.3042.00
Microsoft SQL Server 2005 Tools 9.2.3042.00

and I want just the first one (with 9.2.3042.00, which is what I'm
interested in).

Now what's puzzling me is if I run this command:
psinfo.exe -S Applications|?{$_ -like "Microsoft SQL Server 2005
[0-9]"}
I get nothing returned - but if I copy the output from psinfo.exe into
a text file and then run that through powershell, I get this:
PSH H:\WindowsPowerShell > get-content c:\work\tmp.txt|?{$_ -match
"Microsoft SQL Server 2005 [0-9]"}
Microsoft SQL Server 2005 9.2.3042.00
PSH H:\WindowsPowerShell >

i.e. the same -match statement picks up the row i want if it's from
get-content but not as the piped output from psinfo.exe. I've done a
get-member on each and they're both system.string.

Am i missing something obvious here?

Thanks, robin.


My System SpecsSystem Spec
Old 08-13-2007   #2 (permalink)
Roman Kuzmin


 
 

Re: Different results from the same -match statement

> Am i missing something obvious here?
Probably, look, you use -like in your command, mot -match

--
Thanks,
Roman Kuzmin
PowerShellFar and FarNET: http://code.google.com/p/farnet/


My System SpecsSystem Spec
Old 08-13-2007   #3 (permalink)
Robin Moffatt


 
 

Re: Different results from the same -match statement

On Aug 13, 12:10 pm, "Roman Kuzmin" <z...@z.z> wrote:
> > Am i missing something obvious here?

>
> Probably, look, you use -like in your command, mot -match
>


d'oh :-)

double d'oh because i've realised that the software listing doesn't
report the latest patch version of sql server

but anyway, my question about the difference between the two
statements stands, I'm just interested to why it is

cheers.

My System SpecsSystem Spec
Old 08-13-2007   #4 (permalink)
Brandon Shell


 
 

Re: Different results from the same -match statement

-like = Wild Card Comparison
-match = Regex Comparison

May I recommend:
PS> Get-help about_Comparison_Operators

p.s. I believe there are native POSH ways to get the info your looking for.
What is your goal?

"Robin Moffatt" <robin.moffatt@gmail.com> wrote in message
news:1187004432.494029.220580@g4g2000hsf.googlegroups.com...
> On Aug 13, 12:10 pm, "Roman Kuzmin" <z...@z.z> wrote:
>> > Am i missing something obvious here?

>>
>> Probably, look, you use -like in your command, mot -match
>>

>
> d'oh :-)
>
> double d'oh because i've realised that the software listing doesn't
> report the latest patch version of sql server
>
> but anyway, my question about the difference between the two
> statements stands, I'm just interested to why it is
>
> cheers.
>


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
If statement with a message VB Script
Help with SQL statement VB Script
Results from Regular Expression Match PowerShell
just a statement 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