同一个模块不同的外壳.为什么? [英] Same module different casing. Why?

查看:82
本文介绍了同一个模块不同的外壳.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows 上的 minikube 和 docker-machine 存在一些问题,确定 hyper-v 模块是否可用.欲了解更多信息:

  • 区别在于模块名称不同.它是hyper-v"与Hyper-V".我逐字节比较了 C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Hyper-V 中的文件.它们是相同的,路径名的大小写相同.

    那么为什么会有不同呢?

    解决方案

    这可能是模块导入方式造成的:

    Import-Module Hyper-v(Get-Command hyper-v\get-vm).Module.Name

    之前的代码会将模块报告为Hyper-v.

    您可以通过执行以下查询来避免此问题:

    @(Get-Module -ListAvailable hyper-v).Name |获得唯一性

    您将获得在所有版本的 PowerShell 和 Windows 的 Build 版本之间保持一致的大小写.

    预期的:但有时会看到:

    注意:为模块安装了两个库,您可以使用 Get-Module -ListAvailable 看到它们.也许这些版本或 Windows 构建或发布版本不同?至少,此信息自 Windows 10 以来是相关的,因为它们不再是固定的.他们可能有助于查明(添加评论).

    There is a bit of a problem going on with minikube and docker-machine on windows, determining if hyper-v module is available. For more information:

    but this is not essential.

    What is, that on two Windows 10 machines, both up-to-date, both with WMF 5.1 (PSVersion 5.1.16299.251) When running Get-Command hyper-v\get-vm we get different results.

    Let me demonstrate:

    The difference is that the module name differs. It's "hyper-v" vs "Hyper-V". I compared byte-for-byte files inside C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Hyper-V. They are the same, and the path name have the same casing.

    So why is the difference?

    解决方案

    This is likely caused by how the module is imported:

    Import-Module Hyper-v
    (Get-Command hyper-v\get-vm).Module.Name
    

    The previous code will report the module as Hyper-v.

    You can avoid this problem with performing the query as follows:

    @(Get-Module -ListAvailable hyper-v).Name | Get-Unique
    

    You will get the casing that is consistent between all version of PowerShell and Build versions of Windows.

    Expected: But this is sometimes seen:

    Note: There are two libraries installed for the modules, which you can see with Get-Module -ListAvailable. Maybe these versions or the Windows build or release version differs? At least, this information is relevant since Windows 10, as they are not fixed anymore. They might help with pinpointing (added comment).

    这篇关于同一个模块不同的外壳.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆