Solved

powershell psobject

Posted on 2016-07-18
10
35 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
  • 5
  • 3
  • 2
10 Comments
 
LVL 39

Assisted Solution

by:footech
footech earned 167 total points
Comment Utility
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 82

Assisted Solution

by:oBdA
oBdA earned 333 total points
Comment Utility
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
Comment Utility
thank you very much. and I can save that as a script and run from schedule task?
0
 
LVL 1

Author Comment

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

Expert Comment

by:footech
Comment Utility
??
it checks for versions.
I don't know what that means.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:Jason Thomas
Comment Utility
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 39

Expert Comment

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

Author Comment

by:Jason Thomas
Comment Utility
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 82

Accepted Solution

by:
oBdA earned 333 total points
Comment Utility
(Get-Item 'C:\Windows\explorer.exe').VersionInfo.ProductVersion

Open in new window

0
 
LVL 1

Author Closing Comment

by:Jason Thomas
Comment Utility
Brilliant as always. Hope point share seems fair.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now