?
Solved

powershell psobject

Posted on 2016-07-18
10
Medium Priority
?
50 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 40

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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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 40

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 40

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

743 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