.net - Powershell Get-SCVirtualDiskDrive 生成​​公共(public)语言规范 (CLR) 错误

标签 .net powershell virtual-machine clr virtualization

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

Get-SCVirtualDiskDrive -VMMServer $VMMServer -VM $VMName

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

格式默认:字段或属性:“Lun”,类型:“Microsoft.SystemCenter.VirtualMachineManager.VirtualDiskDrive”仅在字母大小写方面与字段不同
或属性:“LUN”。该类型必须符合公共(public)语言规范 (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。我真的希望有人可以在这里提供帮助,这不是我第一次遇到问题,但这一次,这是不可避免的。

最佳答案

问题是因为我运行的是 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"

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

    关于.net - Powershell Get-SCVirtualDiskDrive 生成​​公共(public)语言规范 (CLR) 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32971483/

    相关文章:

    c# - 为什么 Windows 服务中的打印屏幕返回黑色图像?

    c# - 使用 PowerShell 发出 POST 请求

    powershell - 如何使用Powershell将foreach输出到CSV中?

    windows - 在 PowerShell v2 中打破 foreach 循环

    c++ - 在 VM 中安全地运行 C++

    hadoop - VirtualBox CentOS 6.4中Accumulo初始化异常

    azure - 尝试通过部署在 tomcat 中的 Web 应用程序连接到 Azure 服务管理 API

    c# - 加载位图时出现内存不足错误

    c# - 为什么 Rhino Stubs 允许我对它们设定期望值?

    c# - 需要从 VB 到 C# 的代码翻译