簡體   English   中英

如何在Powershell命令中設置變量

[英]How to set a variable in a powershell command

我正在嘗試在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 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM