powershell - 如何在 Powershell 中将元素添加到数组前面?

标签 powershell

Powershell 代码:

$list += "aa"

将元素“aa”附加到列表$list。有没有办法在前面添加一个元素?这是我的解决方案,但必须有一种方法可以在一行中完成此操作。

$tmp = ,"aa";
$tmp += $list
$list = $tmp

最佳答案

在上面的示例中,您应该能够执行以下操作:

$list = ,"aa" + $list

这只会将“aa”添加到列表中并使其成为第 0 个元素。通过获取 $list[0] 进行验证。

关于powershell - 如何在 Powershell 中将元素添加到数组前面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2201571/

相关文章:

powershell - 如何在 PowerShell 上更改字体

powershell - 尝试通过 Powershell/MSBuild 远程停止时找不到服务

Azure Powershell : How Do I search for files in a BLOB storage quickly?

node.js - 错误: "The operation was rejected by your operating system" when trying to create new angular project using windows powershell

multithreading - 在以 Start-ThreadJob 启动的线程中使用作用域变量修改 PowerShell $

powershell - 参数powershell的自动完成值

powershell - 授予 MSysObjects 的读取权限

powershell - Power Shell:在内存中使用变量/字符串生成器的最有效方法是什么?

powershell - 您能否在 macOS 上的 Powershell 7 中使用 PtrToStringAuto 来解密安全字符串?

powershell - 使用 Powershell 在没有提示的情况下自动删除文件