'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.
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
- $Result += Get-SCVirtualMachine -Name $vm
-
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [Microsoft.SystemCenter.VirtualMachineManager.VM] does not contain a method named 'op_Addition'. At line:3 char:1
- $Result += Get-SCVirtualMachine -Name $vm
-
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
Get-SCVirtualMachine : Cannot validate argument on parameter 'Name'. The character length (0) of the argument is too short. Specify an argument with a length that is greater than or equal to "1", and then try the command again. At line:3 char:39
- $Result += Get-SCVirtualMachine -Name $vm
-
~~~
- CategoryInfo : InvalidData: (:) [Get-SCVirtualMachine], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.SystemCenter.VirtualMachineManager.Cmdlets.GetVMCmdlet
Solution 1:[1]
I forgot to declare the array $result = @()
I resolved the issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | YScharf |