Help with Windows PowerShell
-
29-09-2019 - |
Question
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
Solution
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()}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow