are there any practical uses for the variables names like ${c:file.txt} ?


are there practical uses variables names ${c:file.txt} ?

these expansions implicit get-content on object named in variable name.

the effect of variable namespace notation may functionally identical implicit "get-content" or "out-file". caution against thinking these cmdlets used. more both same thing using components live @ lower level powershell script.

but if used under hood, speak, variable namespace notation gives no way access functionality provide other -filepath parameter. means limited reading/writing complete text files.

my own personal view feature interesting side effect 1 might find useful in interactive context or in simple scripts. in more significant scripting projects get-content , out-file should preferred because of greater degree of control give, example:

  1. they allow name of file contained in variable, whereas variable namespace notation requires name given literal.
  2. get-content throws error when referencing non-existent file. variable namespace notation returns null value non-existent file.


al dunbar -- remember 'mark or propose answer' or 'vote helpful' appropriate.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

server manager error: ADAM.events.xml could not be enumerated.

Cannot access Anywhere Access using domain name?

WMI Failure: Unable to update Local Resource Group