3

#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}
Filed in: Columns, Tips and Tricks Tags: , ,

3 Responses to "#PSTip Getting the content of an object"

Leave a Reply

Submit Comment

© 2016 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: