当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 比较 Windows PowerShell 和 PowerShell 7 中的变量

作者:精品下载站 日期:2024-12-14 07:32:05 浏览:15 分类:玩电脑

比较 Windows PowerShell 和 PowerShell 7 中的变量


PowerShell 自动变量由 PowerShell 存储和维护。这适用于每个 Windows 操作系统附带的 Windows PowerShell 以及通过 GitHub 下载的 PowerShell。

在这篇博文中,我将展示如何比较 Windows PowerShell 和 PowerShell 7 中的自动变量。

例如,Windows PowerShell 中缺少 $IsWindows 变量。检查是否安装了 Windows 也是没有意义的,因为 Windows PowerShell 仅在 Windows 操作系统上运行。


$IsWindows

[玩转系统] 比较 Windows PowerShell 和 PowerShell 7 中的变量

但我们现在会发现更多差异。

将变量保存在文件中

首先,我们将 Windows PowerShell 变量列表保存在文件中。


Get-Variable | Select-Object -ExpandProperty Name | Out-File C:\Temp\windowspowershellvariables.txt

[玩转系统] 比较 Windows PowerShell 和 PowerShell 7 中的变量

然后我们将 PowerShell 变量保存在文件中。


Get-Variable | Select-Object -ExpandProperty Name | Out-File C:\Temp\powershellvariables.txt

[玩转系统] 比较 Windows PowerShell 和 PowerShell 7 中的变量

比较 Windows PowerShell 和 PowerShell 的变量

以下列表向我们展示了差异:


Compare-Object -ReferenceObject (Get-Content C:\Temp\windowspowershellvariables.txt) `
-DifferenceObject (Get-Content C:\Temp\powershellvariables.txt)

[玩转系统] 比较 Windows PowerShell 和 PowerShell 7 中的变量

要查看与 PowerShell 相比 Windows PowerShell 缺少什么,请运行


(Compare-Object -ReferenceObject (Get-Content C:\Temp\windowspowershellvariables.txt) `
-DifferenceObject (Get-Content C:\Temp\powershellvariables.txt) |
Where-Object {$_.SideIndicator -eq "=>"} |
Select-Object -ExpandProperty InputObject) -join ", "

[玩转系统] 比较 Windows PowerShell 和 PowerShell 7 中的变量

要查看 PowerShell 与 Windows PowerShell 相比缺少什么,请运行


(Compare-Object -ReferenceObject (Get-Content C:\Temp\windowspowershellvariables.txt) `
-DifferenceObject (Get-Content C:\Temp\powershellvariables.txt) |
Where-Object {$_.SideIndicator -eq "<="} |
Select-Object -ExpandProperty InputObject) -join ", "

[玩转系统] 比较 Windows PowerShell 和 PowerShell 7 中的变量

嗯,任务完成了。希望本文能提供有用的信息,特别是对于那些经常使用自动变量的读者。

下次使用 PowerShell 再见!

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯