#PSTip Getting the content of an object

Getting the content of an object is usually done with the Get-Content cmdlet. For example, getting the content of the Windows hosts file:

Get-Content C:\Windows\System32\drivers\etc\hosts

Did you know that Get-Content has a shortcut syntax to do the same?

PS> ${C:\Windows\System32\drivers\etc\hosts}

Here’s how you can get a definition of a function:

PS> ${function:prompt}

Note: Keep in mind that the value in the braces must be a literal, no variables are allowed. This will not work:

PS> ${$env:WINDIR\System32\drivers\etc\hosts}
Share on: