开发者

Load file file with PowerShell?

开发者 https://www.devze.com 2023-03-29 23:05 出处:网络
I would like to l开发者_运维知识库oad a file, contains vars\' statements. For example, VLANS.conf will contain $VLANS = \"VLAN1500\", \"VLAN877\"

I would like to l开发者_运维知识库oad a file, contains vars' statements.

For example, VLANS.conf will contain $VLANS = "VLAN1500", "VLAN877"

How do I load it into powershell?


Read the file content and use the Invoke-Expression cmdlet to evaluate each line as an expression:

PS > Get-Content .\VLANS.conf | Foreach-Object {Invoke-Expression $_}
PS >$VLANS
VLAN1500
VLAN877


Alternative is to have a VLANS.ps1 or VLANS.conf.ps1 or something and "dot source the file"?

. .\VLANS.ps1

You will have the advantage of having here-strings, script blocks ( and of course anything you can have in a powershell script)

0

精彩评论

暂无评论...
验证码 换一张
取 消