Load file file with PowerShell?
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)
精彩评论