lara400
lara400

Reputation: 4736

FileVersion Output is null

any idea why I get nothing back on the below? The file is there on the server I query and if I do it locally it works fine in getting the file version.

$computer = Get-Content -Path c:\temp\servers1.txt

foreach ($server in $computer){

$path = Get-WmiObject Win32_Service -Filter "Name = 'SysMgmtHp'" -ComputerName $server | select pathname

(Get-Command $path).FileVersionInfo.FileVersion

}

Upvotes: 0

Views: 467

Answers (2)

jbockle
jbockle

Reputation: 643

Can you post the output of $path.pathname for service named 'SysMgmtHp'? Several services have additional arguments in .pathname property or wrapped in quotes, you may need to trim these arguments/quotes. Also, post Get-ChildItem $path.pathname | select * results.

Upvotes: 0

Keith Hill
Keith Hill

Reputation: 201632

Try:

(Get-Command $path.pathname).FileVersionInfo.FileVersion

When you use | select pathname that is essentially creating a new object with a pathname property. You can see this by feeding the output to Get-Member which gives you type info and a list of type members e.g.:

PS> Get-WmiObject Win32_Service -Filter "Name = 'Spooler'" | Get-Member


   TypeName: System.Management.ManagementObject#root\cimv2\Win32_Service

Name                    MemberType    Definition
----                    ----------    ----------
PSComputerName          AliasProperty PSComputerName = __SERVER
...

versus

PS> Get-WmiObject Win32_Service -Filter "Name = 'Spooler'" | select pathname| Get-Member


   TypeName: Selected.System.Management.ManagementObject

Name        MemberType   Definition
----        ----------   ----------
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
pathname    NoteProperty System.String pathname=C:\Windows\System32\spoolsv.exe

All that said, you're getting the path of the service on the remote computer and then checking the version on your local computer. If you can enable remoting on the server, you could do this:

Invoke-Command $server { $path = (Get-WmiObject Win32_Service -Filter "Name = 'SysMgmtHp'").PathName; (Get-Command $path).FileVersionInfo.FileVersion }

This will get the file version of the service binary on the remote computer.

Upvotes: 1

Related Questions