Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

powershell psobject

Posted on 2016-07-18
10
Medium Priority
?
52 Views
Last Modified: 2016-07-26
Hi experts.
I want to compare a file on a server with one that is newer (same name but version difference) so I am trying to compare the files version, and if the same version do nothing, if older install newer file.
I have been looking at psobject -property but to be honest PS is not my strength, if the file resides :
\\SERVER1\files\myfile   and the version is 1.
my new file is also called myfile and it's version is version 2. can anyone give me the command I would use please? I'm not one for trying this site everything a problem occurs but as said PS isn't me and it could take me hours to get the answer through googling.
thank you all.
0
Comment
Question by:Jason Thomas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 41

Assisted Solution

by:footech
footech earned 668 total points
ID: 41717514
How is the version of the file designated?  Does it show in the file's versioninfo like
gi \\SERVER1\files\myfile | Select -expand VersionInfo | Select FileVersion

Open in new window


Depending on the answer you may be looking at different ways of comparing a file, like comparing dates, file hashes, etc.
0
 
LVL 85

Assisted Solution

by:oBdA
oBdA earned 1332 total points
ID: 41717544
The correct way to do it depends on the way your actual file defines the version string.
If it's the usual convention of a maximum of 4 int32 separated by '.', it's not difficult.
$OldFile = Get-Item -Path '\\SERVER1\files\myfile'
$NewFile = Get-Item -Path '\\SERVER1\NewFiles\myfile'
If ([version]$OldFile.VersionInfo.FileVersion -lt [version]$NewFile.VersionInfo.FileVersion) {
	Copy-Item -Path $NewFile.FullName -Destination $OldFile.FullName -Force -WhatIf
}

Open in new window

Or if the file date will reflect older/newer:
$OldFile = Get-Item -Path '\\SERVER1\files\myfile'
$NewFile = Get-Item -Path '\\SERVER1\NewFiles\myfile'
If ($OldFile.LastWriteTime -lt $NewFile.LastWriteTime) {
	Copy-Item -Path $NewFile.FullName -Destination $OldFile.FullName -Force -WhatIf
}

Open in new window

0
 
LVL 1

Author Comment

by:Jason Thomas
ID: 41717576
thank you very much. and I can save that as a script and run from schedule task?
0
Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

 
LVL 1

Author Comment

by:Jason Thomas
ID: 41717580
hi@fotech. sorry I'm on a mobile and only saw the second response through my screen. it checks for versions.
0
 
LVL 41

Expert Comment

by:footech
ID: 41717597
??
it checks for versions.
I don't know what that means.
0
 
LVL 1

Author Comment

by:Jason Thomas
ID: 41717604
Hi. first of it looks like my responses are appearing more than once, could be the new EE app I'm using I have no idea. To clarify further as I realise my version answer was a bit vague. so, we look are looking at the file properties, details tab, and "product version" property.
thank you chaps.
0
 
LVL 41

Expert Comment

by:footech
ID: 41717612
oBdA's should work for you then.  Just change FileVersion to ProductVersion.
0
 
LVL 1

Author Comment

by:Jason Thomas
ID: 41719413
Hi both still looking at this. What one liner can I use to pull the file version info for a file? I just want to be able to test and check the version outside of a script.
Thank you.
0
 
LVL 85

Accepted Solution

by:
oBdA earned 1332 total points
ID: 41719417
(Get-Item 'C:\Windows\explorer.exe').VersionInfo.ProductVersion

Open in new window

0
 
LVL 1

Author Closing Comment

by:Jason Thomas
ID: 41728999
Brilliant as always. Hope point share seems fair.
0

Featured Post

Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question