Powershell - 用户输入的数组范围

标签 powershell powershell-2.0

获取数组范围的用户输入的最简单方法是什么。

例如:

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/

相关文章:

powershell - 我想使用 powershell 将时间和日期列添加到 csv 文件

powershell - 无法在 `Register-ObjectEvent` 脚本 block 中调用类方法

powershell排序对象无法按预期工作

PowerShell Tee-Object 不覆盖文件

powershell - 如何使用powershell替换msha文件中的值?

datetime - PowerShell 中的 "Group by day"

powershell - 如何在 Invoke-Command -ArgumentList 中通过引用传递变量

xml - 如何从XML获取参数并执行exe列表?

powershell - 获取内容 powershell commandlet 未返回

powershell - 从 Add-WindowsFeature cmdlet 清除 PowerShell 覆盖