首页 > 系统相关 >Windows PowerShell Compatibility

Windows PowerShell Compatibility

时间:2023-06-29 16:02:45浏览次数:47  
标签:Get Windows module Compatibility Module Import PowerShell

背景

Win11 21H2(OS Build 22000.2124)

Windows PowerShell 7.3.5

简述

在试用 PowerShell 7.x 时,部分命令仍需 PS 5.1 .

具体来说,是指 %windir%\system32\WindowsPowerShell\v1.0\Modules 下的 Module[2],例如 Appx 的 Get-AppxPackage.

Unless the module manifest indicates that module is compatible with PowerShell Core, modules in the %windir%\system32\WindowsPowerShell\v1.0\Modules folder are loaded in a background Windows PowerShell 5.1 process by Windows PowerShell Compatibility feature.

表现

~ $ Get-AppxPackage
Get-AppxPackage: The 'Get-AppxPackage' command was found in the module 'Appx', but the module could not be loaded. 
                 For more information, run 'Import-Module Appx'.

禁用 PS 5.1 的情况下,Import-Module appx 无效。

启用 PS 5.1,则会启用 WinPSCompatSession remoting session.

~ $ Import-Module appx
WARNING: Module Appx is loaded in Windows PowerShell using WinPSCompatSession remoting session; 
         please note that all input and output of commands from this module will be deserialized objects. 
         If you want to load this module into PowerShell please use 'Import-Module -SkipEditionCheck' syntax.

验证 WinPSCompatSession remoting session.

$s = Get-PSSession -Name WinPSCompatSession
Invoke-Command -Session $s -ScriptBlock {
  "Running in Windows PowerShell version $($PSVersionTable.PSVersion)"
}

TEMP 目录

  • remoteIpMoProxy_Appx_2.0.1.0_localhost_ed4a3308-b75a-4eb4-919f-90167dba6ac4

禁用隐式兼容层,DisableImplicitWinCompat

~ $ Import-Module appx
Import-Module: Module 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\appx\appx.psd1' supports PowerShell edition 'Desktop' 
               and cannot be loaded implicitly using the Windows Compatibility feature because it is disabled in the settings file. 
               Use 'Import-Module -UseWindowsPowerShell' to load this module with Windows PowerShell or 'Import-Module -SkipEditionCheck' 
               to try to load the module with the current PowerShell.

参考

更多

Improved backwards compatibility with Windows PowerShell

For Windows, a new switch parameter UseWindowsPowerShell (aliases: UseWinPS) is added to Import-Module. This switch creates a proxy module in PowerShell 7 that uses a local Windows PowerShell process to implicitly run any cmdlets contained in that module. For more information, see Import-Module.

Cmdlet changes: Check system32 for compatible built-in modules on Windows

In the Windows 10 1809 update and Windows Server 2019, we updated a number of built-in PowerShell modules to mark them as compatible with PowerShell.

When PowerShell starts up, it automatically includes $windir\System32 as part of the PSModulePath environment variable. However, it only exposes modules to Get-Module and Import-Module if its CompatiblePSEdition is marked as compatible with Core.

You can override this behavior to show all modules using the -SkipEditionCheck switch parameter. We've also added a PSEdition property to the table output.

Compatible modules

Get-Module -ListAvailable

Beginning in PowerShell 6, the CompatiblePSEditions value is used to decide if a module is compatible when modules are imported from $env:windir\System32\WindowsPowerShell\v1.0\Modules. This behavior only applies to Windows. Outside of this scenario, the value is only used as metadata.

标签:Get,Windows,module,Compatibility,Module,Import,PowerShell
From: https://www.cnblogs.com/UPeRVv/p/17513996.html

相关文章

  • NET6的net6.0-windows10.xxx文件夹
    通常使用.NET6生成window程序默认在bin下会生成对应系统的net6.0-windows10.xxxx之类的文件夹。如果不喜欢的可以在项目文件中编辑增加<PropertyGroup><AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath></PropertyGroup> ......
  • windows环境下使用Jenkins部署.net core
    前言之前学习了windows环境下使用Jenkins配置dotnetcore极简入门-chenxizhaolu-博客园(cnblogs.com)又学习了Windows下使用docker部署.NetCore-chenxizhaolu-博客园(cnblogs.com)现在将两者结合起来,通过Jenkins自动发布.netcore到Docker1、安装Jenkins参照windo......
  • Windows 资源管理器 开启
    有时候任务管理器不小心关闭其Windos资源管理器 然后导致桌面直接黑屏例: 启动文件资源管理器Ctrl+Shift+Esc 启动任务管理器Win11点击运行新任务 输入explorer.exe即可恢复Win10  同win11即可恢复......
  • 微软借Windows Mobile开始反击
    本文发表于2009-10-2008:5010/27/20091:59:56PM微软有点背水一战的味道。10月15日,微软在北京宣布推出首批Windowsphone手机,来自不同手机厂商的17款手机将采用WindowsMobile6.5操作系统,这些手机将于年底上市。在此之前一周,微软已于10月7日,在全球超过20个国家同步发布windows......
  • windows nginx 开机启动
    1、首先下载winsw下载地址:https://github.com/kohsuke/winsw/releaseswinse.NET4.exe或百度云盘:链接:https://pan.baidu.com/s/1-G1dyl1y_WA5ziGV07AHpQ提取码:j8fy或:https://files.cnblogs.com/files/Fooo/nginx%E5%BC%80%E6%9C%BA%E5%90%AF%E5%8A%A8.rar?t=1688009381&d......
  • 苹果恶搞Windows 7
     本文发表于2009-10-2708:54在WindowsVista败走麦城之后,微软指望着能够通过上周四发布的新操作系统Windows7来恢复自己的形象,苹果却不帮这个忙。苹果公司的新广告没兑现的承诺再一次拿微软开起了玩笑,在其正在进行的拥有Mac推广活动中,苹果加入了一个新的诙谐广告,广告中,贾斯汀......
  • Windows下Tomcat的安装配置
    一、下载相应的JDK以及Tomcat的版本JDK:jdk-8u131-windows-x64tomcat:apache-tomcat-8.5.23-windows-x64.zip二、JDK的安装请参考:三、Tomcat的安装第一步:从官网下载apache-tomcat-8.5.23-windows-x64.zip,下载地址:https://tomcat.apache.org/whichversion.html第二步:将下载......
  • windows10/11关闭更新
    windows10/11关闭更新1.regedit打开注册表2.依次打开:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings3.新建DWORDS32位值-->>键名:FlightSettingsMaxPauseDays值设置暂停更新天数4.打开windows设置-->>更新与安全-->>高级选项-->>暂停更新下选择暂停到......
  • windows上传app到构建版本的方法
    ios打包好ipa文件后,ipa文件需要上架到appstore,用户才能安装。而在appstore里,无法直接将ipa上传,需要使用工具上传,但是官方提供的工具,比如xcode等只能安装在苹果电脑上。我们这篇文章,重点将介绍如何使用windows电脑将ipa文件上传appstore的构建版本里和上架的基本流程。上架ipa......
  • django项目在windows的部署(apach+Mod_wsgi+django)
    如果django项目如果要正式使用,我们需要将项目部署到开发环境上去。django项目自带的服务不支持多线程,会出现多个用户访问时,页面卡死,半天打不开的问题。所以,该如何部署django项目呢?下边是我的部署经验,实测有效。如果可以的话,尽量部署到linux上,但是我的系统中涉及到一些window文件......