![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | Re: how to compare in this situation The double quotes are not necessary in the foreach loop. foreach {$dictionary.$($_.name)} -- Kiron |
My System Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 Specs![]() |
| | #7 (permalink) |
| | 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 Specs![]() |
| | #8 (permalink) |
| | 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 Specs![]() |
| | #9 (permalink) |
| | 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 Specs![]() |
| | #10 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||