0

I'm trying to access a method of text file, I use this first:

Get-Item file.txt | get-member

Then I would like to use the GetType() method, but it says it doesn't recognize file.txt as the name of a cmdlet,function,script file or operable problem. I need to access that or any other method :D

1 Answer 1

4

You have a couple of options here. First is to turn the command into an expression by using parens:

(Get-Item file.txt).GetType()

The other option is to use Foreach-Object (aliased to foreach) in the pipeline to execute arbitrary script against pipeline objects where each pipeline object is represented by the special variable $_ e.g.:

Get-Item file.txt | Foreach {$_.GetType()}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.