#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}

About the author: Shay Levy

Shay Levy is a Co-founder and editor of the PowerShell Magazine. He is a multiple-year recipient of the Microsoft MVP award, and a Microsoft Certified Trainer (MCT). Shay often covers PowerShell related topics on his blog and you can also follow him on Twitter at @ShayLevy

Related Posts