windows - 如何在powershell命令中设置变量
问题描述
我正在尝试在 powershell 命令中声明和设置一个变量。那可能吗?
我希望做这样的事情:
"$name" = "I219" | Get-NetAdapter | where Name -Match "$name"
这是可能的还是只能在 .ps 脚本中完成?
解决方案
声明变量后,只需在控制台中按 enter 即可轻松完成:
$name = "I219" # now hit enter
要访问该变量,请在控制台中键入它并再次按 Enter:
$name # hit enter => returns I219
现在将它与您的命令一起使用:
Get-NetAdapter | where { $_.Name -Match $name }
或作为单行:
$name = "I219"; Get-NetAdapter | where { $_.Name -Match $name }
推荐阅读
- angular - Angular 9新项目-ng服务时未加载应用程序根
- javascript - 刷新后的角度重定向并阻止通过直接 url 访问
- verilog - 如何在verilog中将LUT解包到逻辑单元中
- css - Chrome 上不支持内联 css 剪辑路径
- android - imageCache.clear() 在 Flutter 中的 ListView 上不起作用
- reactjs - React 本机元素类型无效。需要一个字符串或类/函数,但未定义
- android - Flutter Signed APK build 中无法打开 zipalign 失败错误
- sql-server - 寻找编写代码逻辑的更好方法
- mysql - MySQL:生成列的表达式包含不允许的函数?康卡特?
- javascript - 打开一个新的后关闭 FeatherLight