获取数组范围的用户输入的最简单方法是什么。
例如:
function MyArrayOfMachines {
[CmdletBinding()]
param(
[parameter(Mandatory=$true)][string]$Machine
# What should I assign the $Range variable as?
)
# Hardcoded range. User should be able to enter the range
$Range = 2..5
for ($i=0; $i -lt $array.length; $i +=1)
{
$result = $array[$i]
$output = $machine+$result
$output
}
}
上述函数应将输入作为机器名称和数组范围。现在我已经对数组范围进行了硬编码。当我在用户提示中将 $Range 指定为 [Array]$Range 时,会提示 $Range[0] 等。但我希望用户输入范围。
最佳答案
这行不通?除非我误解了你的问题...
function test($range){
$range
}
test -range (1..5)
关于Powershell - 用户输入的数组范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7602220/