Get-ChildItem -> Output: Servername | PSChildName | FileVersion

Hi there,

I’m trying my first steps with PowerShell.

Well, there’s a cool feature called Get-ChildItem and $env:COMPUTERNAME.

To get computername: write-host $env:COMPUTERNAME
Got get PSChildName and VersionInfo → FileVersion: Get-ChildItem C:\tmp\my.exe | Format-List -Property “*”

I tried half an hour to get the simple list (write-host, where, fildstr, …) as output but I failed ;(

Servername | PSChildName | FileVersion

Could please somebody give an advice how I get my list?

Best wishes

Mat,
Welcome to the forum. :wave:t4:

We would love to help you further but I have to admit that I didn’t get what you want to do actually. Could you elaborate a little more detailed please?

Regardless of that: When you post code or sample data or console output please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Thanks in advance

Hi Olaf,

thanks a lot for your reply.

It I use Get-ChildItem I can see information PSChildName for my my.exe and VersionInfor → FileVersion 1.0. These information I’d like to display as a short string including computername as pipe seperated list:

Servername | PSChildName | FileVersion

Seems to be very simple but not for me ;(

Hmmm … it is actually quite easy …

$MyExe = Get-Item -Path 'path to your my.exe'
'{0} | {1} | {2}' -f $env:COMPUTERNAME, $MyExe.Name, $MyExe.VersionInfo.FileVersion

May I ask what you actually want to achieve? Whatfor do you want to have the output in such a specific format?

Another option would be this:

$MyExe = Get-Item -Path 'path to your my.exe'
$env:COMPUTERNAME, $MyExe.Name, $MyExe.VersionInfo.FileVersion -join ' | '
1 Like