none
Difference in the Results of PowerShell script RRS feed

  • Question

  • Hello guys,

    I am working on a script to import csv data and convert into hash table. I am able to do with the below script.

    $hash = @{}
    
    $csvs = import-csv F:\email.csv
    
    foreach ( $csv in $csvs )
    
            { $a = $csv.VM
              $b = $csv.Memory  
              $hash.add("$a","$b")
            }
    $hash


    But, I am little confuse, if without declaring the $a and $b variables, I am directly putting up the values like given below

    $hash = @{}
    
    $csvs = import-csv F:\email.csv
    
    foreach ( $csv in $csvs )
    
            { 
              $hash.add("$csv.VM","$csv.Memory")
            }
    
    $hash

    It is giving me result like this

    Name                                   Value                                                                                                                                                 
    ----                           -----                                                                                                                                                 
    @{VM=poclld; Memory=3}.vm      @{VM=poclld; Memory=3}.memory                                                                                                                         
    @{VM=erww; Memory=8}.vm        @{VM=erww; Memory=8}.memory                                                                                                                           
    @{VM=asd; Memory=4}.vm         @{VM=asd; Memory=4}.memory   

    Can anyone help me to understand this behaviour of PowerShell.

    Monday, May 29, 2017 7:24 AM

Answers

All replies