我正在尝试使用 Get-Content 从文件中读取一个数字并将其添加到一个变量中。
然后我将此数字添加到文件中的字符串中,将数字增加 1,然后再次将其保存到文件中。
我试过类似的东西:
$i = Get-Content C:\number.txt
$i++
Set-Content C:\number.txt
number.txt的内容是:1000
但我得到这个错误:
The '++' operator works only on numbers. The operand is a 'System.String'.
At line:2 char:5
+ $i++ <<<<
+ CategoryInfo : InvalidOperation: (1000:String) [], RuntimeException
+ FullyQualifiedErrorId : OperatorRequiresNumber
有没有人知道做这个操作的更好方法?