[英]Error while execution powershell code on System Center Virtual Machine Manager
I'm facing an issue of getting all vms configuration ( using Get-ScVirtualMachine command) into an array from an input file.我面临将所有虚拟机配置(使用 Get-ScVirtualMachine 命令)从输入文件导入数组的问题。
The code is this one below代码是下面这个
$VmsList = Get-Content C:\VmsList.txt
foreach($vm in $VmsList){
$Result += Get-SCVirtualMachine -Name $vm
}
And I have this error我有这个错误
Method invocation failed because [Microsoft.SystemCenter.VirtualMachineManager.VM] does not contain a method named 'op_Addition'.
At line:3 char:1在行:3 字符:1
+ CategoryInfo: InvalidOperation: (op_Addition:String) [], RuntimeException + FullyQualifiedErrorId: MethodNotFound
Method invocation failed because [Microsoft.SystemCenter.VirtualMachineManager.VM] does not contain a method named 'op_Addition'.方法调用失败,因为 [Microsoft.SystemCenter.VirtualMachineManager.VM] 不包含名为“op_Addition”的方法。 At line:3 char:1
在行:3 字符:1
+ CategoryInfo: InvalidOperation: (op_Addition:String) [], RuntimeException + FullyQualifiedErrorId: MethodNotFound
Get-SCVirtualMachine: Cannot validate argument on parameter 'Name'. Get-SCVirtualMachine:无法验证参数“名称”的参数。 The character length (0) of the argument is too short.
参数的字符长度 (0) 太短。 Specify an argument with a length that is greater than or equal to "1", and then try the command again.
指定长度大于或等于“1”的参数,然后重试该命令。 At line:3 char:39
在行:3 字符:39
~~~
I forgot to declare the array $result = @()
我忘了声明数组
$result = @()
I resolved the issue.我解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.