【问题标题】:Powershell Get-SCVirtualDiskDrive generates a Common Language Specification (CLR) errorPowershell Get-SCVirtualDiskDrive 生成​​公共语言规范 (CLR) 错误
【发布时间】:2015-10-06 13:38:41
【问题描述】:

当从 VirtualMachineManager 模块运行 Get-SCVirtualDiskDrive 命令时,没有特别的特殊方式。

Get-SCVirtualDiskDrive -VMMServer $VMMServer -VM $VMName

我收到公共语言特定 (CLS) 错误

format-default :字段或属性:“Lun”,类型:“Microsoft.SystemCenter.VirtualMachineManager.VirtualDiskDrive”仅在字母大小写方面与字段不同 或属性:“LUN”。该类型必须符合公共语言规范 (CLS)。 + CategoryInfo : NotSpecified: (:) [format-default], ExtendedTypeSystemException + FullyQualifiedErrorId : NotACLSComplaintProperty,Microsoft.PowerShell.Commands.FormatDefaultCommand

我很难通过我在网上找到的关于 .NET 和 PowerShell 的一些提示来让这个命令正常工作

这行代码有效

$method1 = [Microsoft.SystemCenter.VirtualMachineManager.VirtualDiskDrive].GetMethod("get_LUN")

我真的希望这行代码能返回一些东西,但不,它什么也没有返回......

$method2 = [Microsoft.SystemCenter.VirtualMachineManager.VirtualDiskDrive].GetMethod("get_Lun")

除了让这条线工作之外,该脚本的目的是扩展虚拟机主 VHD。我真的希望有人可以在这里提供帮助,这不是我第一次遇到问题,但这一次,这是不可避免的。

【问题讨论】:

    标签: .net powershell virtual-machine clr virtualization


    【解决方案1】:

    问题是因为我运行的是 Powershell 第 4 版,而 virtualmachinemanager 模块只能兼容第 2 版。

    留下两个选择

    • 卸载 Window Management Framework 以将 Powershell 降级到版本 2
    • 使用 Start-Process 将脚本作为 Powershell 版本 2 运行

    Start-Process -File PowerShell.exe -Argument "-Version 2 -noprofile -noexit -file test.ps1 $params"

    不理想,我希望有人可以改进这个答案

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-27
      • 1970-01-01
      • 2010-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-10
      相关资源
      最近更新 更多