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 compare in this situation

Reply
 
Old 07-20-2007   #1 (permalink)
IT Staff


 
 

how to compare in this situation

# create hash table
$dictionary = @{}
$dictionary["v1.0."] = "Version 1.0"
$dictionary["v1.1"] = "Version 1.1"
$dictionary["v2.0"] = "Version 2.0"
$dictionary["v3.0"] = "Version 3.0"


$strComputer = $args[0]
$dir = dir "\\$strcomputer\admin$\microsoft.net\Framework"
$folders = $dir | where {$_.mode -match "d" -and $_.name -like "v*"} |
select name

foreach ($folder in $folders)
{
$folder
}
==============================================================

I want to do a $folder comparison with the $dictionary hash tables. If a
$folder name exists in $dictionary hash tables, it will display the
$dictionary.values

How do it do that ?




My System SpecsSystem Spec
Old 07-20-2007   #2 (permalink)
Edengundam


 
 

Re: how to compare in this situation

I think -contains operator will accomplish ur problem and I believe there
are more effective solution for this problem.

just like :

PS C:\Documents and Settings\Eden> $hash = @{}
PS C:\Documents and Settings\Eden> @($hash.keys) -contains 'a'
False
PS C:\Documents and Settings\Eden> $hash['a'] = "test"
PS C:\Documents and Settings\Eden> @($hash.keys) -contains 'a'
True
PS C:\Documents and Settings\Eden>


Edengundam

> # create hash table
> $dictionary = @{}
> $dictionary["v1.0."] = "Version 1.0"
> $dictionary["v1.1"] = "Version 1.1"
> $dictionary["v2.0"] = "Version 2.0"
> $dictionary["v3.0"] = "Version 3.0"
>
>
> $strComputer = $args[0]
> $dir = dir "\\$strcomputer\admin$\microsoft.net\Framework"
> $folders = $dir | where {$_.mode -match "d" -and $_.name -like "v*"} |
> select name
>
> foreach ($folder in $folders)
> {
> $folder
> }
> ==============================================================
>
> I want to do a $folder comparison with the $dictionary hash tables. If a
> $folder name exists in $dictionary hash tables, it will display the
> $dictionary.values
>
> How do it do that ?
>
>
>



My System SpecsSystem Spec
Old 07-20-2007   #3 (permalink)
Kiron


 
 

Re: how to compare in this situation

Use the containment operator -contains. Also use .psIsContainer instead of
..mode -match 'd'.
Here is the one-liner:

dir "\\$strcomputer\admin$\microsoft.net\Framework" | where
{$_.psIsContainer -and $_.name -like "v*" -and $dictionary.keys -contains
$_.name} | foreach {$dictionary."$($_.name)"}

--
Kiron

My System SpecsSystem Spec
Old 07-20-2007   #4 (permalink)
Kiron


 
 

Re: how to compare in this situation

The double quotes are not necessary in the foreach loop.

foreach {$dictionary.$($_.name)}

--
Kiron
My System SpecsSystem Spec
Old 07-20-2007   #5 (permalink)
IT Staff


 
 

Re: how to compare in this situation

Perhaps i m not clear on my questions.

I want to list the remote machine directory and once found it will display
the VALUES.

Version 1.0
Version 1.1
etc




"Kiron" <Kiron@HighPlainsDrifter.com> wrote in message
news:eT0EW6pyHHA.1208@TK2MSFTNGP05.phx.gbl...
> The double quotes are not necessary in the foreach loop.
>
> foreach {$dictionary.$($_.name)}
>
> --
> Kiron



My System SpecsSystem Spec
Old 07-20-2007   #6 (permalink)
RichS


 
 

Re: how to compare in this situation

Part of the problem may be in the names you have in the dictionary. For
instance on my machine the folders are
v1.0.3705
v1.1.4322
v2.0.50215
v2.0.50727
v3.0
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"IT Staff" wrote:

> Perhaps i m not clear on my questions.
>
> I want to list the remote machine directory and once found it will display
> the VALUES.
>
> Version 1.0
> Version 1.1
> etc
>
>
>
>
> "Kiron" <Kiron@HighPlainsDrifter.com> wrote in message
> news:eT0EW6pyHHA.1208@TK2MSFTNGP05.phx.gbl...
> > The double quotes are not necessary in the foreach loop.
> >
> > foreach {$dictionary.$($_.name)}
> >
> > --
> > Kiron

>
>
>

My System SpecsSystem Spec
Old 07-20-2007   #7 (permalink)
RichS


 
 

Re: how to compare in this situation

Try this

$dictionary = @{}
$dictionary["v1.0"] = "Version 1.0"
$dictionary["v1.1"] = "Version 1.1"
$dictionary["v2.0"] = "Version 2.0"
$dictionary["v3.0"] = "Version 3.0"

$dir = dir "c:\windows\microsoft.net\Framework"
$folders = $dir | where {$_.mode -match "d" -and $_.name -like "v*"} |
select name

Foreach ($folder in
$folders){$dictionary[$folder.Name.Tostring().SubString(0,4) ]}

You will need to alter the $dir = .... line for remote machines
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"IT Staff" wrote:

> Perhaps i m not clear on my questions.
>
> I want to list the remote machine directory and once found it will display
> the VALUES.
>
> Version 1.0
> Version 1.1
> etc
>
>
>
>
> "Kiron" <Kiron@HighPlainsDrifter.com> wrote in message
> news:eT0EW6pyHHA.1208@TK2MSFTNGP05.phx.gbl...
> > The double quotes are not necessary in the foreach loop.
> >
> > foreach {$dictionary.$($_.name)}
> >
> > --
> > Kiron

>
>
>

My System SpecsSystem Spec
Old 07-20-2007   #8 (permalink)
IT Staff


 
 

Re: how to compare in this situation

# create hash table
$dictionary = @{}
$dictionary["v1.0.3705"] = "Version 1.0"
$dictionary["v1.1.4322"] = "Version 1.1"
$dictionary["v2.0.50727"] = "Version 2.0"
$dictionary["v3.0"] = "Version 3.0"

I can create the hash table to pre-determine the folder name.

However after running the directory listing, it does not display the
dictionary.values. What i need is the values not keys.


"RichS" <RichS@discussions.microsoft.com> wrote in message
news:F5E66544-20DE-40C9-97A5-0119A26D55BD@microsoft.com...
> Part of the problem may be in the names you have in the dictionary. For
> instance on my machine the folders are
> v1.0.3705
> v1.1.4322
> v2.0.50215
> v2.0.50727
> v3.0
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog: http://richardsiddaway.spaces.live.com/
> PowerShell User Group: http://www.get-psuguk.org.uk
>
>
> "IT Staff" wrote:
>
>> Perhaps i m not clear on my questions.
>>
>> I want to list the remote machine directory and once found it will
>> display
>> the VALUES.
>>
>> Version 1.0
>> Version 1.1
>> etc
>>
>>
>>
>>
>> "Kiron" <Kiron@HighPlainsDrifter.com> wrote in message
>> news:eT0EW6pyHHA.1208@TK2MSFTNGP05.phx.gbl...
>> > The double quotes are not necessary in the foreach loop.
>> >
>> > foreach {$dictionary.$($_.name)}
>> >
>> > --
>> > Kiron

>>
>>
>>



My System SpecsSystem Spec
Old 07-20-2007   #9 (permalink)
Jacques Barathon [MS]


 
 

Re: how to compare in this situation

"IT Staff" <jkklim@hotmail.com> wrote in message
news:e57%23OIryHHA.748@TK2MSFTNGP04.phx.gbl...
># create hash table
> $dictionary = @{}
> $dictionary["v1.0.3705"] = "Version 1.0"
> $dictionary["v1.1.4322"] = "Version 1.1"
> $dictionary["v2.0.50727"] = "Version 2.0"
> $dictionary["v3.0"] = "Version 3.0"
>
> I can create the hash table to pre-determine the folder name.
>
> However after running the directory listing, it does not display the
> dictionary.values. What i need is the values not keys.


Is this what you want?

dir C:\windows\Microsoft.net\Framework | where {$dictionary.keys -contains
$_} | foreach {$dictionary["$_"]}

Jacques

My System SpecsSystem Spec
Old 07-21-2007   #10 (permalink)
dreeschkind


 
 

Re: how to compare in this situation

Another approach would be:

$dictionary = @{}
$dictionary.'v1.0.3705' = 'Version 1.0'
$dictionary.'v1.1.4322' = 'Version 1.1'
$dictionary.'v2.0.50727' = 'Version 2.0'
$dictionary.'v3.0' = 'Version 3.0'

gci $env:windir\Microsoft.net\Framework | ForEach { $dictionary."$_" }

--
greetings
dreeschkind

"Jacques Barathon [MS]" wrote:

> "IT Staff" <jkklim@hotmail.com> wrote in message
> news:e57%23OIryHHA.748@TK2MSFTNGP04.phx.gbl...
> ># create hash table
> > $dictionary = @{}
> > $dictionary["v1.0.3705"] = "Version 1.0"
> > $dictionary["v1.1.4322"] = "Version 1.1"
> > $dictionary["v2.0.50727"] = "Version 2.0"
> > $dictionary["v3.0"] = "Version 3.0"
> >
> > I can create the hash table to pre-determine the folder name.
> >
> > However after running the directory listing, it does not display the
> > dictionary.values. What i need is the values not keys.

>
> Is this what you want?
>
> dir C:\windows\Microsoft.net\Framework | where {$dictionary.keys -contains
> $_} | foreach {$dictionary["$_"]}
>
> Jacques
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: 32 bit or 64 bit in this situation? Vista performance & maintenance
Advice on what to do in my situation General Discussion
Nightmare situation Vista General
Can any one seriously solve this situation? Vista General
A no-quit situation 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