Questions in category: PowerShell (PowerShell)
软件 >> Windows >> PowerShell

1. 检查 PowerShell 的版本

Posted by haifeng on 2023-09-30 23:10:49 last update 2023-09-30 23:10:49 | Answers (0) | 收藏


打开 PowerShell, 键入 $PSVersionTable,  显示如下:

--------------------------------------------

Name                           Value                                                                                                
----                           -----                                                                                                
PSVersion                      5.1.19041.3031                                                                                       
PSEdition                      Desktop                                                                                              
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                              
BuildVersion                   10.0.19041.3031                                                                                      
CLRVersion                     4.0.30319.42000                                                                                      
WSManStackVersion              3.0                                                                                                  
PSRemotingProtocolVersion      2.3                                                                                                  
SerializationVersion           1.1.0.1 

2. Windows 安装 WSL 及 WSL2

Posted by haifeng on 2021-03-10 16:36:43 last update 2021-03-10 16:44:10 | Answers (0) | 收藏


使用管理员打开 PowerShell

输入下面的命令 

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart


Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
PS C:\Windows\system32> dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
部署映像服务和管理工具
版本: 10.0.18362.1379
映像版本: 10.0.18363.1379
启用一个或多个功能
[==========================100.0%==========================]
操作成功完成。
PS C:\Windows\system32>

Remark:  /norestart  表示不重启 (no restart)

在安装 WSL 2 之前, 必须启用“虚拟机平台”可选功能

PS C:\Windows\system32> dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
部署映像服务和管理工具
版本: 10.0.18362.1379
映像版本: 10.0.18363.1379
启用一个或多个功能
[==========================100.0%==========================]
操作成功完成。

 

References:

https://zhuanlan.zhihu.com/p/224753478

 

 

3. 在PowerShell中提取一个类的定义

Posted by haifeng on 2020-09-26 11:18:04 last update 2020-09-26 11:26:47 | Answers (0) | 收藏


PS C:\Users\haife> Get-WmiObject -query "SELECT * FROM meta_class WHERE __class = 'Win32_LogicalDisk'"


   NameSpace:ROOT\cimv2

Name                                Methods              Properties
----                                -------              ----------
Win32_LogicalDisk                   {SetPowerState, R... {Access, Availability, BlockSize, Caption...}

 


如果执行  Get-WmiObject -query "SELECT * FROM meta_class"  ,则返回当前命名空间中所有的类定义。

 

Reference:

https://docs.microsoft.com/zh-cn/windows/win32/wmisdk/retrieving-a-class