简体   繁体   English

在 System Center Virtual Machine Manager 上执行 powershell 代码时出错

[英]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

  • $Result += Get-SCVirtualMachine -Name $vm $Result += 获取 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'.方法调用失败,因为 [Microsoft.SystemCenter.VirtualMachineManager.VM] 不包含名为“op_Addition”的方法。 At line:3 char:1在行:3 字符:1

  • $Result += Get-SCVirtualMachine -Name $vm $Result += 获取 SCVirtualMachine -Name $vm
  •  + 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

  • $Result += Get-SCVirtualMachine -Name $vm $Result += 获取 SCVirtualMachine -Name $vm
  •  ~~~
    • CategoryInfo: InvalidData: (:) [Get-SCVirtualMachine], ParameterBindingValidationException类别信息:无效数据:(:) [Get-SCVirtualMachine],ParameterBindingValidationException
    • FullyQualifiedErrorId: ParameterArgumentValidationError,Microsoft.SystemCenter.VirtualMachineManager.Cmdlets.GetVMCmdlet FullyQualifiedErrorId:ParameterArgumentValidationError,Microsoft.SystemCenter.VirtualMachineManager.Cmdlets.GetVMCmdlet

I forgot to declare the array $result = @()我忘了声明数组$result = @()

I resolved the issue.我解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System Center Configuration Manager - PowerShell 远程处理 - System Center Configuration Manager - PowerShell Remoting 运行在虚拟机上执行PowerShell命令的Azure Runbook时出错 - Error while running Azure runbook which executes PowerShell command on Virtual Machine PowerShell-如何添加Microsoft System Center Service Manager控制台模块 - PowerShell - How to add Microsoft System Center Service Manager Console MODULE 如何在主机中的每个虚拟机中运行Powershell代码 - How to run powershell code in every virtual machine in the host 是否可以在System Center Virtual Machine Manager 2012 R2中重命名VM? - Is there away to rename a VM in System Centre Virtual Machine Manager 2012 R2? 使用 Azure 虚拟机系统分配的托管标识来访问 Azure SQL 从 Z70530184AD4679A - Use a Azure Virtual Machine System-Assigned Managed Identity to access Azure SQL from Powershell 修复PowerShell错误的替代方法“在此系统上禁用脚本的执行” - Alternatives to fix PowerShell error “execution of scripts is disabled on this system” MVC System.Management.Automation Powershell执行中的访问被拒绝错误 - Access Denied error in MVC System.Management.Automation powershell execution 添加While循环后的Powershell脚本代码执行问题 - Powershell Scripting Code Execution Issue After Adding a While Loop AWS System Manager 和 Powershell 脚本 - AWS System Manager and Powershell scripts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM