小编Aws*_*saf的帖子

如何在表达式中增加变量的值?

我有以下代码:

$b = 1
Import-Csv c:\Awsaf\powershell\Beforenew.csv | select name, CustomAttribute1, CustomAttribute2, @{n='Counter';e={$b}} | Export-Csv -NoTypeInformation c:\Awsaf\PowerShell\afternew.csv
Run Code Online (Sandbox Code Playgroud)

我想将$ b的值递增1.我已经尝试了$ b ++,$ b + =,for循环,do-while,似乎没有任何工作.我该怎么做?

我也尝试了以下附加代码,但我无法弄清楚如何增加$ b的值.

$b = 0
Import-CSV c:\Awsaf\powershell\afternew.csv -Delimiter ',' | `
ForEach-Object { $_.Counter = "$b"; return $_ } | `
Export-CSV c:\awsaf\powershell\afterX.csv -Delimiter ',' -NoTypeInformation
Run Code Online (Sandbox Code Playgroud)

powershell

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

powershell ×1