情况。在 Windows 7 SP1 计算机上,我已更新为 Windows6.1-KB2819745-x64-MultiPkg.msu。此外,在 PowerShell 中 $PSVersionTable 现在报告“PSVersion 4.0”。
目前,我的结论是许多 PowerShell 4 cmdlet(例如 Test-NetConnection)只能在 Windows 8.1 上运行。但是,我想知道是否有一种解决方法可以在我的 Windows 7 计算机上导入 PowerShell 4 模块。
你不能。它们依赖于较新操作系统(8.0 或 8.1)的基础功能,并且无法移植回 Windows 7。另一种方法是编写您自己的函数/模块,以使用 .NET 框架方法复制新的 cmdlet。
例如,获取文件哈希 https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Get-FileHashcmdlet 在 PowerShell 4.0 中是单行代码,但要在 2.0 中复制,我们必须使用 .NET。
PowerShell v4
Get-FileHash -Algorithm SHA1 "C:\Windows\explorer.exe"
PowerShell v2
$SHA1 = new-object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider
$file = [System.IO.File]::Open("C:\Windows\explorer.exe",[System.IO.Filemode]::Open, [System.IO.FileAccess]::Read)
[System.BitConverter]::ToString($SHA1.ComputeHash($file)) -replace "-",""
$file.Close()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)