Using shorthand to put a Property in an array doesn’t work on some servers

Hi, any help appreciated, got some servers running same version of PS (v2.0) with same directory/file structure yet the PS behaviour is different.

My first attempt to search for files and put its Fullname property into an array was successful on some servers, but brought back a null (blank) result when run on other servers, even though the file and directory structure is the same:

$Configfile = (Get-ChildItem -path $Path -Recurse | Where-Object { ! $_.PSIsContainer } | Where-Object {$_.Name -like "*.exe.config"}).FullName 

I had to revert to the long hand method of “Select -ExpandProperty” to get consistent results across servers:

 $Configfile = Get-ChildItem -path $Path -Recurse | Where-Object { ! $_.PSIsContainer } | Where-Object {$_.Name -like "*.exe.config"} | Select -ExpandProperty FullName 

Anyone any idea why would the first method which is what I usually use not work on some servers running same version of PS?

submitted by /u/londonrex
[link] [comments]

Leave a Reply