Welcome to Powergui.org - an open source community for Windows Powershell

PowerGUI.org PowerGUI.org and blogs

Forums » Active Directory and PowerShell

Thread: File version over the network

This question is answered.


Permlink Replies: 12 - Pages: 1 - Last Post: Nov 26, 2009 9:04 AM by: Shay Levy
fabrigatti

Posts: 30
Registered: 10/1/09
File version over the network
Posted: Nov 25, 2009 7:43 AM
 
  Click to reply to this thread Reply

Hello,


Is it possible to get the version of a file of a remote computer?

Do I have to use "Get-Wmiobject"?


Thank you very much

Fabrizio.




Shay Levy


Posts: 1,346
Registered: 1/31/08
Re: File version over the network
Posted: Nov 25, 2009 8:50 AM   in response to: fabrigatti
 
  Click to reply to this thread Reply

No need to use WMI:


(dir \\serverName\c$\windows\system32\notepad.exe).VersionInfo | fl *

Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
fabrigatti

Posts: 30
Registered: 10/1/09
Re: File version over the network
Posted: Nov 26, 2009 1:20 AM   in response to: Shay Levy
 
  Click to reply to this thread Reply


Does ".versioninfo" and / or "fl" require that Powershell has a newer version than 1.0?


seaJhawk


Posts: 436
Registered: 12/15/08
Re: File version over the network
Posted: Nov 26, 2009 3:20 AM   in response to: fabrigatti
 
  Click to reply to this thread Reply

Yes, you need PowerShell v2.

/chris


Shay Levy


Posts: 1,346
Registered: 1/31/08
Re: File version over the network
Posted: Nov 26, 2009 4:38 AM   in response to: fabrigatti
 
  Click to reply to this thread Reply

For PowerShell 1.0:

$unc = "\\server\c$\windows\system32\notepad.exe"
[System.Diagnostics.FileVersionInfo]::GetVersionInfo($unc) | fl *


Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
fabrigatti

Posts: 30
Registered: 10/1/09
Re: File version over the network
Posted: Nov 26, 2009 6:10 AM   in response to: Shay Levy
 
  Click to reply to this thread Reply

I have improved the script like this (basing on Chris suggestion from another thread):

# ping-host function

function ping-host ($server, [int] $timeout = 7000){

$ping = gwmi Win32_PingStatus -filter "Address='$($server)' and timeout=$($timeout)"

$ping = $ping | Add-Member -passThru -force -memberType NoteProperty -name "StatusText" -value ""

switch ($ping.statusCode){

0 {$ping.StatusText = "Success"}11001 {

$ping.StatusText = "Buffer Too Small"}

11002 {$ping.StatusText = "Destination Net Unreachable"}11003 {

$ping.StatusText = "Destination Host Unreachable"}

11004 {$ping.StatusText = "Destination Protocol Unreachable"}11005 {

$ping.StatusText = "Destination Port Unreachable"}

11006 {$ping.StatusText = "No Resources"}11007 {

$ping.StatusText = "Bad Option"}

11008 {$ping.StatusText = "Hardware Error"}11009 {

$ping.StatusText = "Packet Too Big"}

11010 {$ping.StatusText = "Request Timed Out"}11011 {

$ping.StatusText = "Bad Request"}

11012 {$ping.StatusText = "Bad Route"}11013 {

$ping.StatusText = "TimeToLive Expired Transit"}

11014 {$ping.StatusText = "TimeToLive Expired Reassembly"}11015 {

$ping.StatusText = "Parameter Problem"}

11016 {$ping.StatusText = "Source Quench"}11017 {

$ping.StatusText = "Option Too Big"}

11018 {$ping.StatusText = "Bad Destination"}11032 {

$ping.StatusText = "Negotiating IPSEC"}

11050 {$ping.StatusText = "General Failure"}

default {$ping.StatusText = "Unknown"}

}

$ping

}


get-content "C:\PCCheck.txt" | foreach{

# $_


If ((ping-host $_).statusText -eq "Success"){

$unc = "\\$_\c$\Program Files\Mobiliti\Unplugged\MNUAGENT.exe"

$_

[System.Diagnostics.FileVersionInfo]::GetVersionInfo($unc) | fl ProductName,ProductVersion

}


Else

{


"$_ not reachable" | Write-Host


}


}


Below you can find some of the resultsI get. When the execution of the script encounter a PC for which the credentials are insufficient (or for which the browsing would result as "Logon Failure: The target account name is incorrect"), I get the following (ref. the bottom part):

XDREOE001

ProductName : Network/Unplugged

ProductVersion : 4, 7, 0, 0



XDREOE002 not reachable

XDREOE003
Exception calling "GetVersionInfo" with "1" argument(s): "\\XDREOE003\c$\program files\mobiliti\unplugged\bin\MNUAGENT.exe"

At :line:74 char:53

+ [System.Diagnostics.FileVersionInfo]::GetVersionInfo <<<< ($unc) | fl ProductName,ProductVersion




Shay Levy


Posts: 1,346
Registered: 1/31/08
Re: File version over the network
Posted: Nov 26, 2009 6:30 AM   in response to: fabrigatti
 
  Click to reply to this thread Reply

When the error occur, doe's it terminate the script?

Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
fabrigatti

Posts: 30
Registered: 10/1/09
Re: File version over the network
Posted: Nov 26, 2009 6:34 AM   in response to: Shay Levy
 
  Click to reply to this thread Reply

Yes, the error terminates the script.
No more computers are processed after it.


Shay Levy


Posts: 1,346
Registered: 1/31/08
Re: File version over the network
Posted: Nov 26, 2009 6:45 AM   in response to: fabrigatti
Answered
  Click to reply to this thread Reply

Add a trap statment before the ping check

trap { continue }

if((ping-host $_).statusText -eq "Success"){ ...



Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
fabrigatti

Posts: 30
Registered: 10/1/09
Re: File version over the network
Posted: Nov 26, 2009 7:03 AM   in response to: Shay Levy
 
  Click to reply to this thread Reply

Adding a trap the script continues. Good!

How should I set an IF condition which shows "Machinename not browsable" whenever the trap lets the script continue?

If trap???
{

"$_ not browsable" | Write-Host

}



Thanks
Fabrizio.




Shay Levy


Posts: 1,346
Registered: 1/31/08
Re: File version over the network
Posted: Nov 26, 2009 7:53 AM   in response to: fabrigatti
 
  Click to reply to this thread Reply

Try with this (remove the else clause):


if ((ping-host $_).statusText -eq "Success"){
 
 $computer =$_

 trap {
  write-warning "$computer not reachable"
 }
 
 $unc = "\\$_\c$\Program Files\Mobiliti\Unplugged\MNUAGENT.exe"
 [System.Diagnostics.FileVersionInfo]::GetVersionInfo($unc) | select ProductName,ProductVersion
}




Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
fabrigatti

Posts: 30
Registered: 10/1/09
Re: File version over the network
Posted: Nov 26, 2009 8:45 AM   in response to: Shay Levy
 
  Click to reply to this thread Reply

At first unreachable machine, this is what I get:

WARNING: RESOLS001 not browsable

Exception calling "GetVersionInfo" with "1" argument(s): "\\RESOLS001\c$\program files\mobiliti\unplugged\bin\MNUAGENT.exe"

At :line:78 char:53

+ [System.Diagnostics.FileVersionInfo]::GetVersionInfo <<<< ($unc) | fl ProductName,ProductVersion




Shay Levy


Posts: 1,346
Registered: 1/31/08
Re: File version over the network
Posted: Nov 26, 2009 9:03 AM   in response to: fabrigatti
 
  Click to reply to this thread Reply

I missed the continue keyword inside trap, add it back:
 

trap {
 write-warning ...
 continue
}


Message was edited by: Shay Levy

Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
Legend
MVP: 2501 + pts
Guru: 2001 - 2500 pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums