Looping through a hash, or using an array in PowerShell

后端 未结 7 1646
暗喜
暗喜 2020-12-22 21:13

I\'m using this (simplified) chunk of code to extract a set of tables from SQL Server with BCP.

$OutputDirectory = \"c:\\junk\\\"
$ServerOption =   \"-SServe         


        
7条回答
  •  悲&欢浪女
    2020-12-22 21:35

    Here is another quick way, just using the key as an index into the hash table to get the value:

    $hash = @{
        'a' = 1;
        'b' = 2;
        'c' = 3
    };
    
    foreach($key in $hash.keys) {
        Write-Host ("Key = " + $key + " and Value = " + $hash[$key]);
    }
    

提交回复
热议问题