我有以下代码:$srv_range = 29..30+40+50..52$srv_range.GetType()$NewVMTemplate = New-Object psobject$NewVMTemplate | Add-Member -MemberType NoteProperty -Name Name -Value $null$srv_range | % { $pod= $_ $servers = @() 1..2 | % { $server = $NewVMTemplate | Select-Object * $server.Name = "pod" + "{0:D2}" -f $pod + "-srv" + $_ $servers += $server } ForEach ( $server in $servers) { write-host $server.Name }} 输出:PowerCLI C:\ .\eraseme.ps1IsPublic IsSerial Name BaseType-------- -------- ---- --------True True Object[] System.Arraypod29-srv1pod29-srv2pod30-srv1pod30-srv2pod40-srv1pod40-srv2pod50-srv1pod50-srv2pod51-srv1pod51-srv2pod52-srv1pod52-srv2我想从CLI输入范围,但是用此代码得到以下输出param( [Parameter(Mandatory=$False)] $srv_range)#$srv_range = 29..30+40+50..52$srv_range.GetType()$NewVMTemplate = New-Object psobject$NewVMTemplate | Add-Member -MemberType NoteProperty -Name Name -Value $null$srv_range | % { $pod= $_ $servers = @() 1..2 | % { $server = $NewVMTemplate | Select-Object * $server.Name = "pod" + "{0:D2}" -f $pod + "-srv" + $_ $servers += $server } ForEach ( $server in $servers) { write-host $server.Name }} PowerCLI C:\ .\eraseme.ps1 29..30+40+50..52IsPublic IsSerial Name BaseType-------- -------- ---- --------True True String System.Objectpod29..30+40+50..52-srv1pod29..30+40+50..52-srv2如何从CLI输入范围并获得与第一个代码相同的结果?
添加回答
举报
0/150
提交
取消