Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 17945

PowerShell Get-ChildItem Not always returning a Directory Name

$
0
0

I am searching the drives of multiple servers for a specific file. The code looks something like this...

$filename="db2cmd.exe"        $listOfDrives=(get-psdrive | ? { $_.provider -match 'FileSystem'}).root        foreach ($Drive in $listOfDrives){            If ($Drive -ne "C:\" -and $Drive -ne "A:\") {                Get-ChildItem -Path $Drive -Filter $filename -Recurse -ErrorAction SilentlyContinue -Force            }         }

When I run it, in most instances, when the file is encountered, it returns the Directory where the file was found..

` Directory: E:\IBM\DB2\SQLLIB\BIN

Mode LastWriteTime Length Name PSComputerName


-a---- 1/5/2024 11:32 AM 55888 db2cmd.exe ServerA `

Yet on other servers, neither the Directory nor the Column titles are displayed.

-a---- 1/5/2024 11:32 AM 55888 db2cmd.exe ServerB

I really do not understand the reason for this as it is running the same command on each server. Any help you can provide would be appreciated.

I have tried different parameters, but they seem to change where and what the Get-ChildItems is looking for, and not the way the results are output.


Viewing all articles
Browse latest Browse all 17945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>