I am trying to develop a script that queries a list of server and runs the below command to get the file versions. It looks in the dir listed and searches all subdirectories for anything with *.exe and reports the file version. The command below works and I am trying to figure out how to run this against multiple servers (txt file). I know how to run get-content to access the server list but I am confused at how to query the remote servers because Get-ChildItem does not have -ComputerName.
Can I use invoke-command? What other options do I have?
I looked into this further and have this working fine. Just need help with formatting the output to include the servername.
$servers = Get-Content -Path C:\Aventura\PowershellScripts\RodServers.txt
ForEach ($server in $servers) { invoke-command -computername $server {Get-ChildItem "C:\Program Files\ccleaner\" -Include *.exe -Recurse |Select-Object -ExpandProperty VersionInfo | select-object FileDescription, OriginalFilename, FileVersion | ft -AutoSize}}
I would like to have the servername included in the output. What is the easiest way to accomplish this?
Stop using Format-Table on the remote machine. The output would normally include the computername when it gets to your computer. Format it there. The column is PSComputerName, but it isn’t added until the output hits your machine. When you have th remote machine formatting, you’re preventing it from doing what you want :). Formatting is semi-evil.
And I don’t think you need the ForEach. invoke-command can accept multiple computer names and in fact will parallelize the task for you. You’re actually just slowing it down.
Thanks again for all the help. Much appreciated. I see the PSComputername when I remove the -ft. What is the bst option to get output to look like a table but by not using -ft?
Sorry…Trying to learn something new here.
FYI - Invoke-command works fine as well…and quicker.