是否可以从 Windows Server 2016 Nano 上的 powershell 命令获取 Windows 版本?

War*_*n P 8 powershell windows-server-2016

我正在使用 Windows Server 2016 nano 的最新预览版。

使用远程 powershell 会话,我通过 连接到远程系统Enter-PSSession,然后我尝试使用最常用的技术来检查 Windows 版本,因为完整的 .Net 框架不可用。此外,Get-WmiObject cmdlet 不可用。

我可以看到一些信息的唯一方法是使用这个非 powershell 命令 DISM:

Dism /Online /Get-Feature
Run Code Online (Sandbox Code Playgroud)

这给了我这个输出以及已安装功能的列表:

Deployment Image Servicing and Management tool
Version: 10.0.10514.0

Image Version: 10.0.10514.0

Features listing for package : Microsoft-Windows-Foundation-Package~31bf3856ad364e35~amd64~~10.0.10514.0
Run Code Online (Sandbox Code Playgroud)

从高于我的 Windows 10 桌面的 10514 值,我可以对内核构建有所了解,有趣的是,Windows 10 桌面具有相同的“Microsoft-Windows-Foundation-Package”,但内核构建较低数字。

有没有人找到可以编写的 cmdlet 或一些 powershell 函数或别名,它们会为我检测到我的 powershell 脚本正在以某种不太可能中断的方式在 nano-server 上运行的事实,或者任何命令实际上打印出“Windows Server 2016 Nano Server”?

更新:这更接近我想要的,但有点黑客:

  Get-Item -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion'
Run Code Online (Sandbox Code Playgroud)

更新 2:Get-WmiObject 不存在,虽然以下有效,但它只报告内核版本:

[System.Environment]::OSVersion.Version
Run Code Online (Sandbox Code Playgroud)

上面会报告 build 10514,而 Windows 10 客户端操作系统 RTM 目前报告 10240,但上面确实是“内核构建”,而不是操作系统产品/版本/服务包级别。

Dri*_*104 4

您可以尝试以下操作,我没有纳米服务器可以尝试。放下select如果它给你带来了其他东西,

\n\n
Get-CIMInstance -ClassName Win32_OperatingSystem -Property * | select caption\n
Run Code Online (Sandbox Code Playgroud)\n\n

在真实的 Nano 实例上进行测试时,不需要 -session 参数,但如果您在将来的某个日期需要它,这里是带有 -session 的变体:

\n\n
$cuser = "Your username"\n$cservername = "Your Servername"\n$csession = New-CimSession \xe2\x80\x93Credential $cuser \xe2\x80\x93ComputerName $cservername\nGet-CIMInstance \xe2\x80\x93session $csession -ClassName Win32_OperatingSystem -Property * | select caption\n
Run Code Online (Sandbox Code Playgroud)\n